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

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

Issue 3001103002: Do not qualify with dart:: except where necessary (Closed)
Patch Set: Created 3 years, 4 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
« no previous file with comments | « runtime/vm/kernel_reader.h ('k') | runtime/vm/kernel_to_il.h » ('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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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/kernel_reader.h" 5 #include "vm/kernel_reader.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include "vm/dart_api_impl.h" 9 #include "vm/dart_api_impl.h"
10 #include "vm/kernel_binary.h" 10 #include "vm/kernel_binary.h"
(...skipping 21 matching lines...) Expand all
32 zone_(translation_helper_.zone()), 32 zone_(translation_helper_.zone()),
33 simple_value_(NULL), 33 simple_value_(NULL),
34 builder_(builder) {} 34 builder_(builder) {}
35 35
36 bool IsSimple(intptr_t kernel_offset) { 36 bool IsSimple(intptr_t kernel_offset) {
37 AlternativeReadingScope alt(builder_->reader_, kernel_offset); 37 AlternativeReadingScope alt(builder_->reader_, kernel_offset);
38 uint8_t payload = 0; 38 uint8_t payload = 0;
39 Tag tag = builder_->ReadTag(&payload); // read tag. 39 Tag tag = builder_->ReadTag(&payload); // read tag.
40 switch (tag) { 40 switch (tag) {
41 case kBigIntLiteral: { 41 case kBigIntLiteral: {
42 const dart::String& literal_str = 42 const String& literal_str =
43 H.DartString(builder_->ReadStringReference(), 43 H.DartString(builder_->ReadStringReference(),
44 Heap::kOld); // read index into string table. 44 Heap::kOld); // read index into string table.
45 simple_value_ = &Integer::ZoneHandle(Z, Integer::New(literal_str)); 45 simple_value_ = &Integer::ZoneHandle(Z, Integer::New(literal_str));
46 if (simple_value_->IsNull()) { 46 if (simple_value_->IsNull()) {
47 H.ReportError("Integer literal %s is out of range", 47 H.ReportError("Integer literal %s is out of range",
48 literal_str.ToCString()); 48 literal_str.ToCString());
49 UNREACHABLE(); 49 UNREACHABLE();
50 } 50 }
51 *simple_value_ = H.Canonicalize(*simple_value_); 51 *simple_value_ = H.Canonicalize(*simple_value_);
52 return true; 52 return true;
(...skipping 27 matching lines...) Expand all
80 Heap::kOld)); // read string reference. 80 Heap::kOld)); // read string reference.
81 *simple_value_ = H.Canonicalize(*simple_value_); 81 *simple_value_ = H.Canonicalize(*simple_value_);
82 return true; 82 return true;
83 case kTrueLiteral: 83 case kTrueLiteral:
84 simple_value_ = &Bool::Handle(Z, Bool::Get(true).raw()); 84 simple_value_ = &Bool::Handle(Z, Bool::Get(true).raw());
85 return true; 85 return true;
86 case kFalseLiteral: 86 case kFalseLiteral:
87 simple_value_ = &Bool::Handle(Z, Bool::Get(false).raw()); 87 simple_value_ = &Bool::Handle(Z, Bool::Get(false).raw());
88 return true; 88 return true;
89 case kNullLiteral: 89 case kNullLiteral:
90 simple_value_ = &dart::Instance::ZoneHandle(Z, dart::Instance::null()); 90 simple_value_ = &Instance::ZoneHandle(Z, Instance::null());
91 return true; 91 return true;
92 default: 92 default:
93 return false; 93 return false;
94 } 94 }
95 } 95 }
96 96
97 const dart::Instance& SimpleValue() { return *simple_value_; } 97 const Instance& SimpleValue() { return *simple_value_; }
98 dart::Zone* zone() const { return zone_; } 98 Zone* zone() const { return zone_; }
99 99
100 private: 100 private:
101 TranslationHelper& translation_helper_; 101 TranslationHelper& translation_helper_;
102 dart::Zone* zone_; 102 Zone* zone_;
103 dart::Instance* simple_value_; 103 Instance* simple_value_;
104 StreamingFlowGraphBuilder* builder_; 104 StreamingFlowGraphBuilder* builder_;
105 }; 105 };
106 106
107 RawArray* KernelReader::MakeFunctionsArray() { 107 RawArray* KernelReader::MakeFunctionsArray() {
108 const intptr_t len = functions_.length(); 108 const intptr_t len = functions_.length();
109 const Array& res = Array::Handle(zone_, Array::New(len, Heap::kOld)); 109 const Array& res = Array::Handle(zone_, Array::New(len, Heap::kOld));
110 for (intptr_t i = 0; i < len; i++) { 110 for (intptr_t i = 0; i < len; i++) {
111 res.SetAt(i, *functions_[i]); 111 res.SetAt(i, *functions_[i]);
112 } 112 }
113 return res.raw(); 113 return res.raw();
114 } 114 }
115 115
116 RawLibrary* BuildingTranslationHelper::LookupLibraryByKernelLibrary( 116 RawLibrary* BuildingTranslationHelper::LookupLibraryByKernelLibrary(
117 NameIndex library) { 117 NameIndex library) {
118 return reader_->LookupLibrary(library).raw(); 118 return reader_->LookupLibrary(library).raw();
119 } 119 }
120 120
121 RawClass* BuildingTranslationHelper::LookupClassByKernelClass(NameIndex klass) { 121 RawClass* BuildingTranslationHelper::LookupClassByKernelClass(NameIndex klass) {
122 return reader_->LookupClass(klass).raw(); 122 return reader_->LookupClass(klass).raw();
123 } 123 }
124 124
125 KernelReader::KernelReader(Program* program) 125 KernelReader::KernelReader(Program* program)
126 : program_(program), 126 : program_(program),
127 thread_(dart::Thread::Current()), 127 thread_(Thread::Current()),
128 zone_(thread_->zone()), 128 zone_(thread_->zone()),
129 isolate_(thread_->isolate()), 129 isolate_(thread_->isolate()),
130 scripts_(Array::ZoneHandle(zone_)), 130 scripts_(Array::ZoneHandle(zone_)),
131 patch_classes_(Array::ZoneHandle(zone_)), 131 patch_classes_(Array::ZoneHandle(zone_)),
132 translation_helper_(this, thread_), 132 translation_helper_(this, thread_),
133 builder_(&translation_helper_, 133 builder_(&translation_helper_,
134 zone_, 134 zone_,
135 program_->kernel_data(), 135 program_->kernel_data(),
136 program_->kernel_data_size()) { 136 program_->kernel_data_size()) {
137 T.active_class_ = &active_class_; 137 T.active_class_ = &active_class_;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 175
176 Object& KernelReader::ReadProgram() { 176 Object& KernelReader::ReadProgram() {
177 LongJumpScope jump; 177 LongJumpScope jump;
178 if (setjmp(*jump.Set()) == 0) { 178 if (setjmp(*jump.Set()) == 0) {
179 intptr_t length = program_->library_count(); 179 intptr_t length = program_->library_count();
180 for (intptr_t i = 0; i < length; i++) { 180 for (intptr_t i = 0; i < length; i++) {
181 ReadLibrary(library_offset(i)); 181 ReadLibrary(library_offset(i));
182 } 182 }
183 183
184 for (intptr_t i = 0; i < length; i++) { 184 for (intptr_t i = 0; i < length; i++) {
185 dart::Library& library = LookupLibrary(library_canonical_name(i)); 185 Library& library = LookupLibrary(library_canonical_name(i));
186 if (!library.Loaded()) library.SetLoaded(); 186 if (!library.Loaded()) library.SetLoaded();
187 } 187 }
188 188
189 if (ClassFinalizer::ProcessPendingClasses(/*from_kernel=*/true)) { 189 if (ClassFinalizer::ProcessPendingClasses(/*from_kernel=*/true)) {
190 // If 'main' is not found return a null library, this is the case 190 // If 'main' is not found return a null library, this is the case
191 // when bootstrapping is in progress. 191 // when bootstrapping is in progress.
192 NameIndex main = program_->main_method(); 192 NameIndex main = program_->main_method();
193 if (main == -1) { 193 if (main == -1) {
194 return dart::Library::Handle(Z); 194 return Library::Handle(Z);
195 } 195 }
196 196
197 NameIndex main_library = H.EnclosingName(main); 197 NameIndex main_library = H.EnclosingName(main);
198 dart::Library& library = LookupLibrary(main_library); 198 Library& library = LookupLibrary(main_library);
199 // Sanity check that we can find the main entrypoint. 199 // Sanity check that we can find the main entrypoint.
200 ASSERT(library.LookupObjectAllowPrivate(H.DartSymbol("main")) != 200 ASSERT(library.LookupObjectAllowPrivate(H.DartSymbol("main")) !=
201 Object::null()); 201 Object::null());
202 return library; 202 return library;
203 } 203 }
204 } 204 }
205 205
206 // Either class finalization failed or we caught a compile error. 206 // Either class finalization failed or we caught a compile error.
207 // In both cases sticky error would be set. 207 // In both cases sticky error would be set.
208 Error& error = Error::Handle(Z); 208 Error& error = Error::Handle(Z);
209 error = thread_->sticky_error(); 209 error = thread_->sticky_error();
210 thread_->clear_sticky_error(); 210 thread_->clear_sticky_error();
211 return error; 211 return error;
212 } 212 }
213 213
214 void KernelReader::ReadLibrary(intptr_t kernel_offset) { 214 void KernelReader::ReadLibrary(intptr_t kernel_offset) {
215 builder_.SetOffset(kernel_offset); 215 builder_.SetOffset(kernel_offset);
216 LibraryHelper library_helper(&builder_); 216 LibraryHelper library_helper(&builder_);
217 library_helper.ReadUntilIncluding(LibraryHelper::kCanonicalName); 217 library_helper.ReadUntilIncluding(LibraryHelper::kCanonicalName);
218 dart::Library& library = LookupLibrary(library_helper.canonical_name_); 218 Library& library = LookupLibrary(library_helper.canonical_name_);
219 if (library.Loaded()) return; 219 if (library.Loaded()) return;
220 220
221 library_helper.ReadUntilIncluding(LibraryHelper::kName); 221 library_helper.ReadUntilIncluding(LibraryHelper::kName);
222 library.SetName(H.DartSymbol(library_helper.name_index_)); 222 library.SetName(H.DartSymbol(library_helper.name_index_));
223 223
224 // The bootstrapper will take care of creating the native wrapper classes, but 224 // The bootstrapper will take care of creating the native wrapper classes, but
225 // we will add the synthetic constructors to them here. 225 // we will add the synthetic constructors to them here.
226 if (library.name() == 226 if (library.name() ==
227 Symbols::Symbol(Symbols::kDartNativeWrappersLibNameId).raw()) { 227 Symbols::Symbol(Symbols::kDartNativeWrappersLibNameId).raw()) {
228 ASSERT(library.LoadInProgress()); 228 ASSERT(library.LoadInProgress());
229 } else { 229 } else {
230 library.SetLoadInProgress(); 230 library.SetLoadInProgress();
231 } 231 }
232 // Setup toplevel class (which contains library fields/procedures). 232 // Setup toplevel class (which contains library fields/procedures).
233 233
234 StringIndex import_uri_index = 234 StringIndex import_uri_index =
235 H.CanonicalNameString(library_helper.canonical_name_); 235 H.CanonicalNameString(library_helper.canonical_name_);
236 library_helper.ReadUntilIncluding(LibraryHelper::kSourceUriIndex); 236 library_helper.ReadUntilIncluding(LibraryHelper::kSourceUriIndex);
237 Script& script = ScriptAt(library_helper.source_uri_index_, import_uri_index); 237 Script& script = ScriptAt(library_helper.source_uri_index_, import_uri_index);
238 238
239 dart::Class& toplevel_class = dart::Class::Handle( 239 Class& toplevel_class =
240 Z, dart::Class::New(library, Symbols::TopLevel(), script, 240 Class::Handle(Z, Class::New(library, Symbols::TopLevel(), script,
241 TokenPosition::kNoSource)); 241 TokenPosition::kNoSource));
242 toplevel_class.set_is_cycle_free(); 242 toplevel_class.set_is_cycle_free();
243 library.set_toplevel_class(toplevel_class); 243 library.set_toplevel_class(toplevel_class);
244 244
245 const GrowableObjectArray& classes = 245 const GrowableObjectArray& classes =
246 GrowableObjectArray::Handle(Z, I->object_store()->pending_classes()); 246 GrowableObjectArray::Handle(Z, I->object_store()->pending_classes());
247 247
248 library_helper.ReadUntilExcluding(LibraryHelper::kClasses); 248 library_helper.ReadUntilExcluding(LibraryHelper::kClasses);
249 249
250 // Load all classes. 250 // Load all classes.
251 int class_count = builder_.ReadListLength(); // read list length. 251 int class_count = builder_.ReadListLength(); // read list length.
252 for (intptr_t i = 0; i < class_count; ++i) { 252 for (intptr_t i = 0; i < class_count; ++i) {
253 classes.Add(ReadClass(library, toplevel_class), Heap::kOld); 253 classes.Add(ReadClass(library, toplevel_class), Heap::kOld);
254 } 254 }
255 255
256 fields_.Clear(); 256 fields_.Clear();
257 functions_.Clear(); 257 functions_.Clear();
258 ActiveClassScope active_class_scope(&active_class_, &toplevel_class); 258 ActiveClassScope active_class_scope(&active_class_, &toplevel_class);
259 // Load toplevel fields. 259 // Load toplevel fields.
260 intptr_t field_count = builder_.ReadListLength(); // read list length. 260 intptr_t field_count = builder_.ReadListLength(); // read list length.
261 for (intptr_t i = 0; i < field_count; ++i) { 261 for (intptr_t i = 0; i < field_count; ++i) {
262 intptr_t field_offset = builder_.ReaderOffset(); 262 intptr_t field_offset = builder_.ReaderOffset();
263 ActiveMemberScope active_member_scope(&active_class_, NULL); 263 ActiveMemberScope active_member_scope(&active_class_, NULL);
264 FieldHelper field_helper(&builder_); 264 FieldHelper field_helper(&builder_);
265 field_helper.ReadUntilExcluding(FieldHelper::kName); 265 field_helper.ReadUntilExcluding(FieldHelper::kName);
266 266
267 const dart::String& name = builder_.ReadNameAsFieldName(); 267 const String& name = builder_.ReadNameAsFieldName();
268 field_helper.SetJustRead(FieldHelper::kName); 268 field_helper.SetJustRead(FieldHelper::kName);
269 field_helper.ReadUntilExcluding(FieldHelper::kType); 269 field_helper.ReadUntilExcluding(FieldHelper::kType);
270 const Object& script_class = 270 const Object& script_class =
271 ClassForScriptAt(toplevel_class, field_helper.source_uri_index_); 271 ClassForScriptAt(toplevel_class, field_helper.source_uri_index_);
272 dart::Field& field = dart::Field::Handle( 272 Field& field = Field::Handle(
273 Z, dart::Field::NewTopLevel(name, field_helper.IsFinal(), 273 Z,
274 field_helper.IsConst(), script_class, 274 Field::NewTopLevel(name, field_helper.IsFinal(), field_helper.IsConst(),
275 field_helper.position_)); 275 script_class, field_helper.position_));
276 field.set_kernel_offset(field_offset); 276 field.set_kernel_offset(field_offset);
277 const AbstractType& type = T.BuildType(); // read type. 277 const AbstractType& type = T.BuildType(); // read type.
278 field.SetFieldType(type); 278 field.SetFieldType(type);
279 field_helper.SetJustRead(FieldHelper::kType); 279 field_helper.SetJustRead(FieldHelper::kType);
280 field_helper.ReadUntilExcluding(FieldHelper::kInitializer); 280 field_helper.ReadUntilExcluding(FieldHelper::kInitializer);
281 intptr_t field_initializer_offset = builder_.ReaderOffset(); 281 intptr_t field_initializer_offset = builder_.ReaderOffset();
282 field.set_has_initializer(builder_.PeekTag() == kSomething); 282 field.set_has_initializer(builder_.PeekTag() == kSomething);
283 field_helper.ReadUntilExcluding(FieldHelper::kEnd); 283 field_helper.ReadUntilExcluding(FieldHelper::kEnd);
284 TypedData& kernel_data = builder_.reader_->CopyDataToVMHeap( 284 TypedData& kernel_data = builder_.reader_->CopyDataToVMHeap(
285 Z, field_offset, builder_.ReaderOffset()); 285 Z, field_offset, builder_.ReaderOffset());
(...skipping 17 matching lines...) Expand all
303 intptr_t procedure_count = builder_.ReadListLength(); // read list length. 303 intptr_t procedure_count = builder_.ReadListLength(); // read list length.
304 for (intptr_t i = 0; i < procedure_count; ++i) { 304 for (intptr_t i = 0; i < procedure_count; ++i) {
305 ReadProcedure(library, toplevel_class, false); 305 ReadProcedure(library, toplevel_class, false);
306 } 306 }
307 307
308 toplevel_class.SetFunctions(Array::Handle(MakeFunctionsArray())); 308 toplevel_class.SetFunctions(Array::Handle(MakeFunctionsArray()));
309 309
310 classes.Add(toplevel_class, Heap::kOld); 310 classes.Add(toplevel_class, Heap::kOld);
311 } 311 }
312 312
313 void KernelReader::ReadPreliminaryClass(dart::Class* klass, 313 void KernelReader::ReadPreliminaryClass(Class* klass,
314 ClassHelper* class_helper, 314 ClassHelper* class_helper,
315 intptr_t type_parameter_count) { 315 intptr_t type_parameter_count) {
316 // Note: This assumes that ClassHelper is exactly at the position where 316 // Note: This assumes that ClassHelper is exactly at the position where
317 // the length of the type parameters have been read, and that the order in 317 // the length of the type parameters have been read, and that the order in
318 // the binary is as follows: [...], kTypeParameters, kSuperClass, kMixinType, 318 // the binary is as follows: [...], kTypeParameters, kSuperClass, kMixinType,
319 // kImplementedClasses, [...]. 319 // kImplementedClasses, [...].
320 320
321 // Set type parameters. 321 // Set type parameters.
322 ReadAndSetupTypeParameters(*klass, type_parameter_count, *klass, 322 ReadAndSetupTypeParameters(*klass, type_parameter_count, *klass,
323 Function::Handle(Z)); 323 Function::Handle(Z));
324 324
325 // Set super type. Some classes (e.g., Object) do not have one. 325 // Set super type. Some classes (e.g., Object) do not have one.
326 Tag type_tag = builder_.ReadTag(); // read super class type (part 1). 326 Tag type_tag = builder_.ReadTag(); // read super class type (part 1).
327 if (type_tag == kSomething) { 327 if (type_tag == kSomething) {
328 AbstractType& super_type = 328 AbstractType& super_type =
329 T.BuildTypeWithoutFinalization(); // read super class type (part 2). 329 T.BuildTypeWithoutFinalization(); // read super class type (part 2).
330 if (super_type.IsMalformed()) H.ReportError("Malformed super type"); 330 if (super_type.IsMalformed()) H.ReportError("Malformed super type");
331 klass->set_super_type(super_type); 331 klass->set_super_type(super_type);
332 } 332 }
333 333
334 class_helper->SetJustRead(ClassHelper::kSuperClass); 334 class_helper->SetJustRead(ClassHelper::kSuperClass);
335 class_helper->ReadUntilIncluding(ClassHelper::kMixinType); 335 class_helper->ReadUntilIncluding(ClassHelper::kMixinType);
336 336
337 // Build implemented interface types 337 // Build implemented interface types
338 intptr_t interface_count = builder_.ReadListLength(); 338 intptr_t interface_count = builder_.ReadListLength();
339 const dart::Array& interfaces = 339 const Array& interfaces =
340 dart::Array::Handle(Z, dart::Array::New(interface_count, Heap::kOld)); 340 Array::Handle(Z, Array::New(interface_count, Heap::kOld));
341 for (intptr_t i = 0; i < interface_count; i++) { 341 for (intptr_t i = 0; i < interface_count; i++) {
342 const AbstractType& type = 342 const AbstractType& type =
343 T.BuildTypeWithoutFinalization(); // read ith type. 343 T.BuildTypeWithoutFinalization(); // read ith type.
344 if (type.IsMalformed()) H.ReportError("Malformed interface type."); 344 if (type.IsMalformed()) H.ReportError("Malformed interface type.");
345 interfaces.SetAt(i, type); 345 interfaces.SetAt(i, type);
346 } 346 }
347 class_helper->SetJustRead(ClassHelper::kImplementedClasses); 347 class_helper->SetJustRead(ClassHelper::kImplementedClasses);
348 klass->set_interfaces(interfaces); 348 klass->set_interfaces(interfaces);
349 349
350 if (class_helper->is_abstract_) klass->set_is_abstract(); 350 if (class_helper->is_abstract_) klass->set_is_abstract();
351 } 351 }
352 352
353 dart::Class& KernelReader::ReadClass(const dart::Library& library, 353 Class& KernelReader::ReadClass(const Library& library,
354 const dart::Class& toplevel_class) { 354 const Class& toplevel_class) {
355 ClassHelper class_helper(&builder_); 355 ClassHelper class_helper(&builder_);
356 intptr_t class_offset = builder_.ReaderOffset(); 356 intptr_t class_offset = builder_.ReaderOffset();
357 class_helper.ReadUntilIncluding(ClassHelper::kCanonicalName); 357 class_helper.ReadUntilIncluding(ClassHelper::kCanonicalName);
358 dart::Class& klass = LookupClass(class_helper.canonical_name_); 358 Class& klass = LookupClass(class_helper.canonical_name_);
359 359
360 // The class needs to have a script because all the functions in the class 360 // The class needs to have a script because all the functions in the class
361 // will inherit it. The predicate Function::IsOptimizable uses the absence of 361 // will inherit it. The predicate Function::IsOptimizable uses the absence of
362 // a script to detect test functions that should not be optimized. 362 // a script to detect test functions that should not be optimized.
363 if (klass.script() == Script::null()) { 363 if (klass.script() == Script::null()) {
364 class_helper.ReadUntilIncluding(ClassHelper::kSourceUriIndex); 364 class_helper.ReadUntilIncluding(ClassHelper::kSourceUriIndex);
365 klass.set_script(ScriptAt(class_helper.source_uri_index_)); 365 klass.set_script(ScriptAt(class_helper.source_uri_index_));
366 } 366 }
367 if (klass.token_pos() == TokenPosition::kNoSource) { 367 if (klass.token_pos() == TokenPosition::kNoSource) {
368 class_helper.ReadUntilIncluding(ClassHelper::kPosition); 368 class_helper.ReadUntilIncluding(ClassHelper::kPosition);
(...skipping 13 matching lines...) Expand all
382 for (intptr_t i = 0; i < type_parameter_counts; ++i) { 382 for (intptr_t i = 0; i < type_parameter_counts; ++i) {
383 builder_.SkipStringReference(); // read ith name index. 383 builder_.SkipStringReference(); // read ith name index.
384 builder_.SkipDartType(); // read ith bound. 384 builder_.SkipDartType(); // read ith bound.
385 } 385 }
386 class_helper.SetJustRead(ClassHelper::kTypeParameters); 386 class_helper.SetJustRead(ClassHelper::kTypeParameters);
387 } 387 }
388 388
389 fields_.Clear(); 389 fields_.Clear();
390 functions_.Clear(); 390 functions_.Clear();
391 391
392 if (library.raw() == dart::Library::InternalLibrary() && 392 if (library.raw() == Library::InternalLibrary() &&
393 klass.Name() == Symbols::ClassID().raw()) { 393 klass.Name() == Symbols::ClassID().raw()) {
394 // If this is a dart:internal.ClassID class ignore field declarations 394 // If this is a dart:internal.ClassID class ignore field declarations
395 // contained in the Kernel file and instead inject our own const 395 // contained in the Kernel file and instead inject our own const
396 // fields. 396 // fields.
397 klass.InjectCIDFields(); 397 klass.InjectCIDFields();
398 } else { 398 } else {
399 class_helper.ReadUntilExcluding(ClassHelper::kFields); 399 class_helper.ReadUntilExcluding(ClassHelper::kFields);
400 int field_count = builder_.ReadListLength(); // read list length. 400 int field_count = builder_.ReadListLength(); // read list length.
401 for (intptr_t i = 0; i < field_count; ++i) { 401 for (intptr_t i = 0; i < field_count; ++i) {
402 intptr_t field_offset = builder_.ReaderOffset(); 402 intptr_t field_offset = builder_.ReaderOffset();
403 ActiveMemberScope active_member(&active_class_, NULL); 403 ActiveMemberScope active_member(&active_class_, NULL);
404 FieldHelper field_helper(&builder_); 404 FieldHelper field_helper(&builder_);
405 field_helper.ReadUntilExcluding(FieldHelper::kName); 405 field_helper.ReadUntilExcluding(FieldHelper::kName);
406 406
407 const dart::String& name = builder_.ReadNameAsFieldName(); 407 const String& name = builder_.ReadNameAsFieldName();
408 field_helper.SetJustRead(FieldHelper::kName); 408 field_helper.SetJustRead(FieldHelper::kName);
409 field_helper.ReadUntilExcluding(FieldHelper::kType); 409 field_helper.ReadUntilExcluding(FieldHelper::kType);
410 const AbstractType& type = 410 const AbstractType& type =
411 T.BuildTypeWithoutFinalization(); // read type. 411 T.BuildTypeWithoutFinalization(); // read type.
412 field_helper.SetJustRead(FieldHelper::kType); 412 field_helper.SetJustRead(FieldHelper::kType);
413 const Object& script_class = 413 const Object& script_class =
414 ClassForScriptAt(klass, field_helper.source_uri_index_); 414 ClassForScriptAt(klass, field_helper.source_uri_index_);
415 415
416 const bool is_reflectable = 416 const bool is_reflectable =
417 field_helper.position_.IsReal() && 417 field_helper.position_.IsReal() &&
418 !(library.is_dart_scheme() && library.IsPrivate(name)); 418 !(library.is_dart_scheme() && library.IsPrivate(name));
419 dart::Field& field = dart::Field::Handle( 419 Field& field = Field::Handle(
420 Z, 420 Z, Field::New(name, field_helper.IsStatic(),
421 dart::Field::New(name, field_helper.IsStatic(), 421 // In the VM all const fields are implicitly final
422 // In the VM all const fields are implicitly final 422 // whereas in Kernel they are not final because they
423 // whereas in Kernel they are not final because they 423 // are not explicitly declared that way.
424 // are not explicitly declared that way. 424 field_helper.IsFinal() || field_helper.IsConst(),
425 field_helper.IsFinal() || field_helper.IsConst(), 425 field_helper.IsConst(), is_reflectable, script_class,
426 field_helper.IsConst(), is_reflectable, script_class, 426 type, field_helper.position_));
427 type, field_helper.position_));
428 field.set_kernel_offset(field_offset); 427 field.set_kernel_offset(field_offset);
429 field_helper.ReadUntilExcluding(FieldHelper::kInitializer); 428 field_helper.ReadUntilExcluding(FieldHelper::kInitializer);
430 intptr_t field_initializer_offset = builder_.ReaderOffset(); 429 intptr_t field_initializer_offset = builder_.ReaderOffset();
431 field.set_has_initializer(builder_.PeekTag() == kSomething); 430 field.set_has_initializer(builder_.PeekTag() == kSomething);
432 field_helper.ReadUntilExcluding(FieldHelper::kEnd); 431 field_helper.ReadUntilExcluding(FieldHelper::kEnd);
433 TypedData& kernel_data = builder_.reader_->CopyDataToVMHeap( 432 TypedData& kernel_data = builder_.reader_->CopyDataToVMHeap(
434 Z, field_offset, builder_.ReaderOffset()); 433 Z, field_offset, builder_.ReaderOffset());
435 field.set_kernel_data(kernel_data); 434 field.set_kernel_data(kernel_data);
436 { 435 {
437 // GenerateFieldAccessors reads (some of) the initializer. 436 // GenerateFieldAccessors reads (some of) the initializer.
(...skipping 11 matching lines...) Expand all
449 } 448 }
450 449
451 class_helper.ReadUntilExcluding(ClassHelper::kConstructors); 450 class_helper.ReadUntilExcluding(ClassHelper::kConstructors);
452 int constructor_count = builder_.ReadListLength(); // read list length. 451 int constructor_count = builder_.ReadListLength(); // read list length.
453 for (intptr_t i = 0; i < constructor_count; ++i) { 452 for (intptr_t i = 0; i < constructor_count; ++i) {
454 intptr_t constructor_offset = builder_.ReaderOffset(); 453 intptr_t constructor_offset = builder_.ReaderOffset();
455 ActiveMemberScope active_member_scope(&active_class_, NULL); 454 ActiveMemberScope active_member_scope(&active_class_, NULL);
456 ConstructorHelper constructor_helper(&builder_); 455 ConstructorHelper constructor_helper(&builder_);
457 constructor_helper.ReadUntilExcluding(ConstructorHelper::kFunction); 456 constructor_helper.ReadUntilExcluding(ConstructorHelper::kFunction);
458 457
459 const dart::String& name = 458 const String& name =
460 H.DartConstructorName(constructor_helper.canonical_name_); 459 H.DartConstructorName(constructor_helper.canonical_name_);
461 Function& function = dart::Function::ZoneHandle( 460 Function& function = Function::ZoneHandle(
462 Z, dart::Function::New(name, RawFunction::kConstructor, 461 Z, Function::New(name, RawFunction::kConstructor,
463 false, // is_static 462 false, // is_static
464 constructor_helper.IsConst(), 463 constructor_helper.IsConst(),
465 false, // is_abstract 464 false, // is_abstract
466 constructor_helper.IsExternal(), 465 constructor_helper.IsExternal(),
467 false, // is_native 466 false, // is_native
468 klass, constructor_helper.position_)); 467 klass, constructor_helper.position_));
469 function.set_end_token_pos(constructor_helper.end_position_); 468 function.set_end_token_pos(constructor_helper.end_position_);
470 functions_.Add(&function); 469 functions_.Add(&function);
471 function.set_kernel_offset(constructor_offset); 470 function.set_kernel_offset(constructor_offset);
472 function.set_result_type(T.ReceiverType(klass)); 471 function.set_result_type(T.ReceiverType(klass));
473 472
474 FunctionNodeHelper function_node_helper(&builder_); 473 FunctionNodeHelper function_node_helper(&builder_);
475 function_node_helper.ReadUntilExcluding( 474 function_node_helper.ReadUntilExcluding(
476 FunctionNodeHelper::kRequiredParameterCount); 475 FunctionNodeHelper::kRequiredParameterCount);
477 builder_.SetupFunctionParameters(klass, function, 476 builder_.SetupFunctionParameters(klass, function,
478 true, // is_method 477 true, // is_method
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 Z, class_offset, class_offset_after_annotations); 509 Z, class_offset, class_offset_after_annotations);
511 library.AddClassMetadata(klass, toplevel_class, TokenPosition::kNoSource, 510 library.AddClassMetadata(klass, toplevel_class, TokenPosition::kNoSource,
512 class_offset, &header_data); 511 class_offset, &header_data);
513 } 512 }
514 513
515 class_helper.ReadUntilExcluding(ClassHelper::kEnd); 514 class_helper.ReadUntilExcluding(ClassHelper::kEnd);
516 515
517 return klass; 516 return klass;
518 } 517 }
519 518
520 void KernelReader::ReadProcedure(const dart::Library& library, 519 void KernelReader::ReadProcedure(const Library& library,
521 const dart::Class& owner, 520 const Class& owner,
522 bool in_class) { 521 bool in_class) {
523 intptr_t procedure_offset = builder_.ReaderOffset(); 522 intptr_t procedure_offset = builder_.ReaderOffset();
524 ProcedureHelper procedure_helper(&builder_); 523 ProcedureHelper procedure_helper(&builder_);
525 524
526 procedure_helper.ReadUntilExcluding(ProcedureHelper::kAnnotations); 525 procedure_helper.ReadUntilExcluding(ProcedureHelper::kAnnotations);
527 const dart::String& name = 526 const String& name = H.DartProcedureName(procedure_helper.canonical_name_);
528 H.DartProcedureName(procedure_helper.canonical_name_);
529 bool is_method = in_class && !procedure_helper.IsStatic(); 527 bool is_method = in_class && !procedure_helper.IsStatic();
530 bool is_abstract = procedure_helper.IsAbstract(); 528 bool is_abstract = procedure_helper.IsAbstract();
531 bool is_external = procedure_helper.IsExternal(); 529 bool is_external = procedure_helper.IsExternal();
532 dart::String* native_name = NULL; 530 String* native_name = NULL;
533 intptr_t annotation_count; 531 intptr_t annotation_count;
534 if (is_external) { 532 if (is_external) {
535 // Maybe it has a native implementation, which is not external as far as 533 // Maybe it has a native implementation, which is not external as far as
536 // the VM is concerned because it does have an implementation. Check for 534 // the VM is concerned because it does have an implementation. Check for
537 // an ExternalName annotation and extract the string from it. 535 // an ExternalName annotation and extract the string from it.
538 annotation_count = builder_.ReadListLength(); // read list length. 536 annotation_count = builder_.ReadListLength(); // read list length.
539 for (int i = 0; i < annotation_count; ++i) { 537 for (int i = 0; i < annotation_count; ++i) {
540 if (builder_.PeekTag() != kConstructorInvocation && 538 if (builder_.PeekTag() != kConstructorInvocation &&
541 builder_.PeekTag() != kConstConstructorInvocation) { 539 builder_.PeekTag() != kConstConstructorInvocation) {
542 builder_.SkipExpression(); 540 builder_.SkipExpression();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 582
585 break; 583 break;
586 } 584 }
587 procedure_helper.SetJustRead(ProcedureHelper::kAnnotations); 585 procedure_helper.SetJustRead(ProcedureHelper::kAnnotations);
588 } else { 586 } else {
589 procedure_helper.ReadUntilIncluding(ProcedureHelper::kAnnotations); 587 procedure_helper.ReadUntilIncluding(ProcedureHelper::kAnnotations);
590 annotation_count = procedure_helper.annotation_count_; 588 annotation_count = procedure_helper.annotation_count_;
591 } 589 }
592 const Object& script_class = 590 const Object& script_class =
593 ClassForScriptAt(owner, procedure_helper.source_uri_index_); 591 ClassForScriptAt(owner, procedure_helper.source_uri_index_);
594 dart::Function& function = dart::Function::ZoneHandle( 592 Function& function = Function::ZoneHandle(
595 Z, Function::New(name, GetFunctionType(procedure_helper.kind_), 593 Z, Function::New(name, GetFunctionType(procedure_helper.kind_),
596 !is_method, // is_static 594 !is_method, // is_static
597 false, // is_const 595 false, // is_const
598 is_abstract, is_external, 596 is_abstract, is_external,
599 native_name != NULL, // is_native 597 native_name != NULL, // is_native
600 script_class, procedure_helper.position_)); 598 script_class, procedure_helper.position_));
601 function.set_end_token_pos(procedure_helper.end_position_); 599 function.set_end_token_pos(procedure_helper.end_position_);
602 functions_.Add(&function); 600 functions_.Add(&function);
603 function.set_kernel_offset(procedure_offset); 601 function.set_kernel_offset(procedure_offset);
604 602
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 const Class& parameterized_class, 674 const Class& parameterized_class,
677 const Function& parameterized_function) { 675 const Function& parameterized_function) {
678 ASSERT(type_parameter_count >= 0); 676 ASSERT(type_parameter_count >= 0);
679 if (type_parameter_count == 0) { 677 if (type_parameter_count == 0) {
680 return; 678 return;
681 } 679 }
682 // First setup the type parameters, so if any of the following code uses it 680 // First setup the type parameters, so if any of the following code uses it
683 // (in a recursive way) we're fine. 681 // (in a recursive way) we're fine.
684 TypeArguments& type_parameters = 682 TypeArguments& type_parameters =
685 TypeArguments::Handle(Z, TypeArguments::null()); 683 TypeArguments::Handle(Z, TypeArguments::null());
686 dart::TypeParameter& parameter = dart::TypeParameter::Handle(Z); 684 TypeParameter& parameter = TypeParameter::Handle(Z);
687 Type& null_bound = Type::Handle(Z, Type::null()); 685 Type& null_bound = Type::Handle(Z, Type::null());
688 686
689 // Step a) Create array of [TypeParameter] objects (without bound). 687 // Step a) Create array of [TypeParameter] objects (without bound).
690 type_parameters = TypeArguments::New(type_parameter_count); 688 type_parameters = TypeArguments::New(type_parameter_count);
691 { 689 {
692 AlternativeReadingScope alt(builder_.reader_); 690 AlternativeReadingScope alt(builder_.reader_);
693 for (intptr_t i = 0; i < type_parameter_count; i++) { 691 for (intptr_t i = 0; i < type_parameter_count; i++) {
694 parameter = dart::TypeParameter::New( 692 parameter = TypeParameter::New(
695 parameterized_class, parameterized_function, i, 693 parameterized_class, parameterized_function, i,
696 H.DartSymbol(builder_.ReadStringReference()), // read ith name index. 694 H.DartSymbol(builder_.ReadStringReference()), // read ith name index.
697 null_bound, TokenPosition::kNoSource); 695 null_bound, TokenPosition::kNoSource);
698 type_parameters.SetTypeAt(i, parameter); 696 type_parameters.SetTypeAt(i, parameter);
699 builder_.SkipDartType(); // read guard. 697 builder_.SkipDartType(); // read guard.
700 } 698 }
701 } 699 }
702 700
703 ASSERT(set_on.IsClass() || set_on.IsFunction()); 701 ASSERT(set_on.IsClass() || set_on.IsFunction());
704 if (set_on.IsClass()) { 702 if (set_on.IsClass()) {
(...skipping 17 matching lines...) Expand all
722 AbstractType& bound = 720 AbstractType& bound =
723 T.BuildTypeWithoutFinalization(); // read ith bound. 721 T.BuildTypeWithoutFinalization(); // read ith bound.
724 if (bound.IsMalformedOrMalbounded()) { 722 if (bound.IsMalformedOrMalbounded()) {
725 bound = I->object_store()->object_type(); 723 bound = I->object_store()->object_type();
726 } 724 }
727 parameter.set_bound(bound); 725 parameter.set_bound(bound);
728 } 726 }
729 } 727 }
730 } 728 }
731 729
732 const Object& KernelReader::ClassForScriptAt(const dart::Class& klass, 730 const Object& KernelReader::ClassForScriptAt(const Class& klass,
733 intptr_t source_uri_index) { 731 intptr_t source_uri_index) {
734 Script& correct_script = ScriptAt(source_uri_index); 732 Script& correct_script = ScriptAt(source_uri_index);
735 if (klass.script() != correct_script.raw()) { 733 if (klass.script() != correct_script.raw()) {
736 // Use cache for patch classes. This works best for in-order usages. 734 // Use cache for patch classes. This works best for in-order usages.
737 PatchClass& patch_class = PatchClass::ZoneHandle(Z); 735 PatchClass& patch_class = PatchClass::ZoneHandle(Z);
738 patch_class ^= patch_classes_.At(source_uri_index); 736 patch_class ^= patch_classes_.At(source_uri_index);
739 if (patch_class.IsNull() || patch_class.origin_class() != klass.raw()) { 737 if (patch_class.IsNull() || patch_class.origin_class() != klass.raw()) {
740 patch_class = PatchClass::New(klass, correct_script); 738 patch_class = PatchClass::New(klass, correct_script);
741 patch_classes_.SetAt(source_uri_index, patch_class); 739 patch_classes_.SetAt(source_uri_index, patch_class);
742 } 740 }
743 return patch_class; 741 return patch_class;
744 } 742 }
745 return klass; 743 return klass;
746 } 744 }
747 745
748 Script& KernelReader::ScriptAt(intptr_t index, StringIndex import_uri) { 746 Script& KernelReader::ScriptAt(intptr_t index, StringIndex import_uri) {
749 Script& script = Script::ZoneHandle(Z); 747 Script& script = Script::ZoneHandle(Z);
750 script ^= scripts_.At(index); 748 script ^= scripts_.At(index);
751 if (script.IsNull()) { 749 if (script.IsNull()) {
752 // Create script with correct uri(s). 750 // Create script with correct uri(s).
753 dart::String& uri_string = builder_.SourceTableUriFor(index); 751 String& uri_string = builder_.SourceTableUriFor(index);
754 dart::String& import_uri_string = 752 String& import_uri_string =
755 import_uri == -1 ? uri_string : H.DartString(import_uri, Heap::kOld); 753 import_uri == -1 ? uri_string : H.DartString(import_uri, Heap::kOld);
756 script = Script::New(import_uri_string, uri_string, 754 script = Script::New(import_uri_string, uri_string,
757 builder_.GetSourceFor(index), RawScript::kKernelTag); 755 builder_.GetSourceFor(index), RawScript::kKernelTag);
758 script.set_kernel_script_index(index); 756 script.set_kernel_script_index(index);
759 script.set_kernel_string_offsets(H.string_offsets()); 757 script.set_kernel_string_offsets(H.string_offsets());
760 script.set_kernel_string_data(H.string_data()); 758 script.set_kernel_string_data(H.string_data());
761 script.set_kernel_canonical_names(H.canonical_names()); 759 script.set_kernel_canonical_names(H.canonical_names());
762 scripts_.SetAt(index, script); 760 scripts_.SetAt(index, script);
763 761
764 script.set_line_starts(builder_.GetLineStartsFor(index)); 762 script.set_line_starts(builder_.GetLineStartsFor(index));
765 script.set_debug_positions(Array::Handle(Array::null())); 763 script.set_debug_positions(Array::Handle(Array::null()));
766 script.set_yield_positions(Array::Handle(Array::null())); 764 script.set_yield_positions(Array::Handle(Array::null()));
767 } 765 }
768 return script; 766 return script;
769 } 767 }
770 768
771 void KernelReader::GenerateFieldAccessors(const dart::Class& klass, 769 void KernelReader::GenerateFieldAccessors(const Class& klass,
772 const dart::Field& field, 770 const Field& field,
773 FieldHelper* field_helper, 771 FieldHelper* field_helper,
774 intptr_t field_offset) { 772 intptr_t field_offset) {
775 Tag tag = builder_.PeekTag(); 773 Tag tag = builder_.PeekTag();
776 if (field_helper->IsStatic() && tag == kNothing) { 774 if (field_helper->IsStatic() && tag == kNothing) {
777 // Static fields without an initializer are implicitly initialized to null. 775 // Static fields without an initializer are implicitly initialized to null.
778 // We do not need a getter. 776 // We do not need a getter.
779 field.SetStaticValue(Instance::Handle(Z), true); 777 field.SetStaticValue(Instance::Handle(Z), true);
780 return; 778 return;
781 } 779 }
782 if (tag == kSomething) { 780 if (tag == kSomething) {
(...skipping 15 matching lines...) Expand all
798 // Note: optimizer relies on DoubleInitialized bit in its field-unboxing 796 // Note: optimizer relies on DoubleInitialized bit in its field-unboxing
799 // heuristics. See JitOptimizer::VisitStoreInstanceField for more details. 797 // heuristics. See JitOptimizer::VisitStoreInstanceField for more details.
800 field.RecordStore(converter.SimpleValue()); 798 field.RecordStore(converter.SimpleValue());
801 if (!converter.SimpleValue().IsNull() && 799 if (!converter.SimpleValue().IsNull() &&
802 converter.SimpleValue().IsDouble()) { 800 converter.SimpleValue().IsDouble()) {
803 field.set_is_double_initialized(true); 801 field.set_is_double_initialized(true);
804 } 802 }
805 } 803 }
806 } 804 }
807 805
808 const dart::String& getter_name = 806 const String& getter_name = H.DartGetterName(field_helper->canonical_name_);
809 H.DartGetterName(field_helper->canonical_name_);
810 const Object& script_class = 807 const Object& script_class =
811 ClassForScriptAt(klass, field_helper->source_uri_index_); 808 ClassForScriptAt(klass, field_helper->source_uri_index_);
812 Function& getter = Function::ZoneHandle( 809 Function& getter = Function::ZoneHandle(
813 Z, 810 Z,
814 Function::New( 811 Function::New(
815 getter_name, 812 getter_name,
816 field_helper->IsStatic() ? RawFunction::kImplicitStaticFinalGetter 813 field_helper->IsStatic() ? RawFunction::kImplicitStaticFinalGetter
817 : RawFunction::kImplicitGetter, 814 : RawFunction::kImplicitGetter,
818 field_helper->IsStatic(), 815 field_helper->IsStatic(),
819 // The functions created by the parser have is_const for static fields 816 // The functions created by the parser have is_const for static fields
(...skipping 10 matching lines...) Expand all
830 getter.set_kernel_data(TypedData::Handle(Z, field.kernel_data())); 827 getter.set_kernel_data(TypedData::Handle(Z, field.kernel_data()));
831 getter.set_end_token_pos(field_helper->end_position_); 828 getter.set_end_token_pos(field_helper->end_position_);
832 getter.set_kernel_offset(field_offset); 829 getter.set_kernel_offset(field_offset);
833 getter.set_result_type(AbstractType::Handle(Z, field.type())); 830 getter.set_result_type(AbstractType::Handle(Z, field.type()));
834 getter.set_is_debuggable(false); 831 getter.set_is_debuggable(false);
835 SetupFieldAccessorFunction(klass, getter); 832 SetupFieldAccessorFunction(klass, getter);
836 833
837 if (!field_helper->IsStatic() && !field_helper->IsFinal()) { 834 if (!field_helper->IsStatic() && !field_helper->IsFinal()) {
838 // Only static fields can be const. 835 // Only static fields can be const.
839 ASSERT(!field_helper->IsConst()); 836 ASSERT(!field_helper->IsConst());
840 const dart::String& setter_name = 837 const String& setter_name = H.DartSetterName(field_helper->canonical_name_);
841 H.DartSetterName(field_helper->canonical_name_);
842 Function& setter = Function::ZoneHandle( 838 Function& setter = Function::ZoneHandle(
843 Z, Function::New(setter_name, RawFunction::kImplicitSetter, 839 Z, Function::New(setter_name, RawFunction::kImplicitSetter,
844 false, // is_static 840 false, // is_static
845 false, // is_const 841 false, // is_const
846 false, // is_abstract 842 false, // is_abstract
847 false, // is_external 843 false, // is_external
848 false, // is_native 844 false, // is_native
849 script_class, field_helper->position_)); 845 script_class, field_helper->position_));
850 functions_.Add(&setter); 846 functions_.Add(&setter);
851 setter.set_kernel_data(TypedData::Handle(Z, field.kernel_data())); 847 setter.set_kernel_data(TypedData::Handle(Z, field.kernel_data()));
852 setter.set_end_token_pos(field_helper->end_position_); 848 setter.set_end_token_pos(field_helper->end_position_);
853 setter.set_kernel_offset(field_offset); 849 setter.set_kernel_offset(field_offset);
854 setter.set_result_type(Object::void_type()); 850 setter.set_result_type(Object::void_type());
855 setter.set_is_debuggable(false); 851 setter.set_is_debuggable(false);
856 SetupFieldAccessorFunction(klass, setter); 852 SetupFieldAccessorFunction(klass, setter);
857 } 853 }
858 } 854 }
859 855
860 void KernelReader::SetupFieldAccessorFunction(const dart::Class& klass, 856 void KernelReader::SetupFieldAccessorFunction(const Class& klass,
861 const dart::Function& function) { 857 const Function& function) {
862 bool is_setter = function.IsImplicitSetterFunction(); 858 bool is_setter = function.IsImplicitSetterFunction();
863 bool is_method = !function.IsStaticFunction(); 859 bool is_method = !function.IsStaticFunction();
864 intptr_t parameter_count = (is_method ? 1 : 0) + (is_setter ? 1 : 0); 860 intptr_t parameter_count = (is_method ? 1 : 0) + (is_setter ? 1 : 0);
865 861
866 function.SetNumOptionalParameters(0, false); 862 function.SetNumOptionalParameters(0, false);
867 function.set_num_fixed_parameters(parameter_count); 863 function.set_num_fixed_parameters(parameter_count);
868 function.set_parameter_types( 864 function.set_parameter_types(
869 Array::Handle(Z, Array::New(parameter_count, Heap::kOld))); 865 Array::Handle(Z, Array::New(parameter_count, Heap::kOld)));
870 function.set_parameter_names( 866 function.set_parameter_names(
871 Array::Handle(Z, Array::New(parameter_count, Heap::kOld))); 867 Array::Handle(Z, Array::New(parameter_count, Heap::kOld)));
872 868
873 intptr_t pos = 0; 869 intptr_t pos = 0;
874 if (is_method) { 870 if (is_method) {
875 function.SetParameterTypeAt(pos, T.ReceiverType(klass)); 871 function.SetParameterTypeAt(pos, T.ReceiverType(klass));
876 function.SetParameterNameAt(pos, Symbols::This()); 872 function.SetParameterNameAt(pos, Symbols::This());
877 pos++; 873 pos++;
878 } 874 }
879 if (is_setter) { 875 if (is_setter) {
880 function.SetParameterTypeAt(pos, AbstractType::dynamic_type()); 876 function.SetParameterTypeAt(pos, AbstractType::dynamic_type());
881 function.SetParameterNameAt(pos, Symbols::Value()); 877 function.SetParameterNameAt(pos, Symbols::Value());
882 pos++; 878 pos++;
883 } 879 }
884 } 880 }
885 881
886 dart::Library& KernelReader::LookupLibrary(NameIndex library) { 882 Library& KernelReader::LookupLibrary(NameIndex library) {
887 dart::Library* handle = NULL; 883 Library* handle = NULL;
888 if (!libraries_.Lookup(library, &handle)) { 884 if (!libraries_.Lookup(library, &handle)) {
889 const dart::String& url = H.DartSymbol(H.CanonicalNameString(library)); 885 const String& url = H.DartSymbol(H.CanonicalNameString(library));
890 handle = 886 handle = &Library::Handle(Z, Library::LookupLibrary(thread_, url));
891 &dart::Library::Handle(Z, dart::Library::LookupLibrary(thread_, url));
892 if (handle->IsNull()) { 887 if (handle->IsNull()) {
893 *handle = dart::Library::New(url); 888 *handle = Library::New(url);
894 handle->Register(thread_); 889 handle->Register(thread_);
895 } 890 }
896 ASSERT(!handle->IsNull()); 891 ASSERT(!handle->IsNull());
897 libraries_.Insert(library, handle); 892 libraries_.Insert(library, handle);
898 } 893 }
899 return *handle; 894 return *handle;
900 } 895 }
901 896
902 dart::Class& KernelReader::LookupClass(NameIndex klass) { 897 Class& KernelReader::LookupClass(NameIndex klass) {
903 dart::Class* handle = NULL; 898 Class* handle = NULL;
904 if (!classes_.Lookup(klass, &handle)) { 899 if (!classes_.Lookup(klass, &handle)) {
905 dart::Library& library = LookupLibrary(H.CanonicalNameParent(klass)); 900 Library& library = LookupLibrary(H.CanonicalNameParent(klass));
906 const dart::String& name = H.DartClassName(klass); 901 const String& name = H.DartClassName(klass);
907 handle = &dart::Class::Handle(Z, library.LookupClass(name)); 902 handle = &Class::Handle(Z, library.LookupClass(name));
908 if (handle->IsNull()) { 903 if (handle->IsNull()) {
909 *handle = dart::Class::New(library, name, Script::Handle(Z), 904 *handle = Class::New(library, name, Script::Handle(Z),
910 TokenPosition::kNoSource); 905 TokenPosition::kNoSource);
911 library.AddClass(*handle); 906 library.AddClass(*handle);
912 } 907 }
913 // Insert the class in the cache before calling ReadPreliminaryClass so 908 // Insert the class in the cache before calling ReadPreliminaryClass so
914 // we do not risk allocating the class again by calling LookupClass 909 // we do not risk allocating the class again by calling LookupClass
915 // recursively from ReadPreliminaryClass for the same class. 910 // recursively from ReadPreliminaryClass for the same class.
916 classes_.Insert(klass, handle); 911 classes_.Insert(klass, handle);
917 } 912 }
918 return *handle; 913 return *handle;
919 } 914 }
920 915
921 RawFunction::Kind KernelReader::GetFunctionType( 916 RawFunction::Kind KernelReader::GetFunctionType(
922 ProcedureHelper::Kind procedure_kind) { 917 ProcedureHelper::Kind procedure_kind) {
923 intptr_t lookuptable[] = { 918 intptr_t lookuptable[] = {
924 RawFunction::kRegularFunction, // Procedure::kMethod 919 RawFunction::kRegularFunction, // Procedure::kMethod
925 RawFunction::kGetterFunction, // Procedure::kGetter 920 RawFunction::kGetterFunction, // Procedure::kGetter
926 RawFunction::kSetterFunction, // Procedure::kSetter 921 RawFunction::kSetterFunction, // Procedure::kSetter
927 RawFunction::kRegularFunction, // Procedure::kOperator 922 RawFunction::kRegularFunction, // Procedure::kOperator
928 RawFunction::kConstructor, // Procedure::kFactory 923 RawFunction::kConstructor, // Procedure::kFactory
929 }; 924 };
930 intptr_t kind = static_cast<int>(procedure_kind); 925 intptr_t kind = static_cast<int>(procedure_kind);
931 ASSERT(0 <= kind && kind <= ProcedureHelper::kFactory); 926 ASSERT(0 <= kind && kind <= ProcedureHelper::kFactory);
932 return static_cast<RawFunction::Kind>(lookuptable[kind]); 927 return static_cast<RawFunction::Kind>(lookuptable[kind]);
933 } 928 }
934 929
935 bool KernelReader::FieldHasFunctionLiteralInitializer(const dart::Field& field, 930 bool KernelReader::FieldHasFunctionLiteralInitializer(const Field& field,
936 TokenPosition* start, 931 TokenPosition* start,
937 TokenPosition* end) { 932 TokenPosition* end) {
938 dart::Zone* zone = Thread::Current()->zone(); 933 Zone* zone = Thread::Current()->zone();
939 const Script& script = Script::Handle(zone, field.Script()); 934 const Script& script = Script::Handle(zone, field.Script());
940 935
941 TranslationHelper translation_helper( 936 TranslationHelper translation_helper(
942 Thread::Current(), script.kernel_string_offsets(), 937 Thread::Current(), script.kernel_string_offsets(),
943 script.kernel_string_data(), script.kernel_canonical_names()); 938 script.kernel_string_data(), script.kernel_canonical_names());
944 939
945 StreamingFlowGraphBuilder builder( 940 StreamingFlowGraphBuilder builder(
946 &translation_helper, zone, field.kernel_offset(), 941 &translation_helper, zone, field.kernel_offset(),
947 TypedData::Handle(zone, field.kernel_data())); 942 TypedData::Handle(zone, field.kernel_data()));
948 kernel::FieldHelper field_helper(&builder); 943 kernel::FieldHelper field_helper(&builder);
949 field_helper.ReadUntilExcluding(kernel::FieldHelper::kEnd, true); 944 field_helper.ReadUntilExcluding(kernel::FieldHelper::kEnd, true);
950 return field_helper.FieldHasFunctionLiteralInitializer(start, end); 945 return field_helper.FieldHasFunctionLiteralInitializer(start, end);
951 } 946 }
952 947
953 ParsedFunction* ParseStaticFieldInitializer(Zone* zone, 948 ParsedFunction* ParseStaticFieldInitializer(Zone* zone, const Field& field) {
954 const dart::Field& field) {
955 Thread* thread = Thread::Current(); 949 Thread* thread = Thread::Current();
956 950
957 dart::String& init_name = dart::String::Handle(zone, field.name()); 951 String& init_name = String::Handle(zone, field.name());
958 init_name = Symbols::FromConcat(thread, Symbols::InitPrefix(), init_name); 952 init_name = Symbols::FromConcat(thread, Symbols::InitPrefix(), init_name);
959 953
960 // Create a static initializer. 954 // Create a static initializer.
961 const Object& owner = Object::Handle(field.RawOwner()); 955 const Object& owner = Object::Handle(field.RawOwner());
962 const Function& initializer_fun = Function::ZoneHandle( 956 const Function& initializer_fun = Function::ZoneHandle(
963 zone, 957 zone, Function::New(init_name, RawFunction::kImplicitStaticFinalGetter,
964 dart::Function::New(init_name, RawFunction::kImplicitStaticFinalGetter,
965 true, // is_static 958 true, // is_static
966 false, // is_const 959 false, // is_const
967 false, // is_abstract 960 false, // is_abstract
968 false, // is_external 961 false, // is_external
969 false, // is_native 962 false, // is_native
970 owner, TokenPosition::kNoSource)); 963 owner, TokenPosition::kNoSource));
971 initializer_fun.set_kernel_data(TypedData::Handle(zone, field.kernel_data())); 964 initializer_fun.set_kernel_data(TypedData::Handle(zone, field.kernel_data()));
972 initializer_fun.set_kernel_offset(field.kernel_offset()); 965 initializer_fun.set_kernel_offset(field.kernel_offset());
973 initializer_fun.set_result_type(AbstractType::Handle(zone, field.type())); 966 initializer_fun.set_result_type(AbstractType::Handle(zone, field.type()));
974 initializer_fun.set_is_debuggable(false); 967 initializer_fun.set_is_debuggable(false);
975 initializer_fun.set_is_reflectable(false); 968 initializer_fun.set_is_reflectable(false);
976 initializer_fun.set_is_inlinable(false); 969 initializer_fun.set_is_inlinable(false);
977 return new (zone) ParsedFunction(thread, initializer_fun); 970 return new (zone) ParsedFunction(thread, initializer_fun);
978 } 971 }
979 972
980 } // namespace kernel 973 } // namespace kernel
981 } // namespace dart 974 } // namespace dart
982 #endif // !defined(DART_PRECOMPILED_RUNTIME) 975 #endif // !defined(DART_PRECOMPILED_RUNTIME)
OLDNEW
« no previous file with comments | « runtime/vm/kernel_reader.h ('k') | runtime/vm/kernel_to_il.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698