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

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

Issue 2481873005: clang-format runtime/vm (Closed)
Patch Set: Merge Created 4 years, 1 month 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/boolfield.h ('k') | runtime/vm/bootstrap_natives.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) 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/bootstrap.h" 5 #include "vm/bootstrap.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 8
9 #include "vm/bootstrap_natives.h" 9 #include "vm/bootstrap_natives.h"
10 #include "vm/class_finalizer.h" 10 #include "vm/class_finalizer.h"
11 #include "vm/compiler.h" 11 #include "vm/compiler.h"
12 #include "vm/dart_api_impl.h" 12 #include "vm/dart_api_impl.h"
13 #include "vm/object.h" 13 #include "vm/object.h"
14 #include "vm/object_store.h" 14 #include "vm/object_store.h"
15 #include "vm/symbols.h" 15 #include "vm/symbols.h"
16 16
17 namespace dart { 17 namespace dart {
18 18
19 #define INIT_LIBRARY(index, name, source, patch) \ 19 #define INIT_LIBRARY(index, name, source, patch) \
20 { index, \ 20 { index, "dart:" #name, source, "dart:" #name "-patch", patch }
21 "dart:"#name, source, \
22 "dart:"#name"-patch", patch } \
23 21
24 typedef struct { 22 typedef struct {
25 ObjectStore::BootstrapLibraryId index_; 23 ObjectStore::BootstrapLibraryId index_;
26 const char* uri_; 24 const char* uri_;
27 const char** source_paths_; 25 const char** source_paths_;
28 const char* patch_uri_; 26 const char* patch_uri_;
29 const char** patch_paths_; 27 const char** patch_paths_;
30 } bootstrap_lib_props; 28 } bootstrap_lib_props;
31 29
32 30
33 enum { 31 enum {
34 kPathsUriOffset = 0, 32 kPathsUriOffset = 0,
35 kPathsFileOffset = 1, 33 kPathsFileOffset = 1,
36 kPathsSourceOffset = 2, 34 kPathsSourceOffset = 2,
37 kPathsEntryLength = 3 35 kPathsEntryLength = 3
38 }; 36 };
39 37
40 38
41 static bootstrap_lib_props bootstrap_libraries[] = { 39 static bootstrap_lib_props bootstrap_libraries[] = {
42 INIT_LIBRARY(ObjectStore::kCore, 40 INIT_LIBRARY(ObjectStore::kCore,
43 core, 41 core,
44 Bootstrap::core_source_paths_, 42 Bootstrap::core_source_paths_,
45 Bootstrap::core_patch_paths_), 43 Bootstrap::core_patch_paths_),
46 INIT_LIBRARY(ObjectStore::kAsync, 44 INIT_LIBRARY(ObjectStore::kAsync,
47 async, 45 async,
48 Bootstrap::async_source_paths_, 46 Bootstrap::async_source_paths_,
49 Bootstrap::async_patch_paths_), 47 Bootstrap::async_patch_paths_),
50 INIT_LIBRARY(ObjectStore::kConvert, 48 INIT_LIBRARY(ObjectStore::kConvert,
51 convert, 49 convert,
52 Bootstrap::convert_source_paths_, 50 Bootstrap::convert_source_paths_,
53 Bootstrap::convert_patch_paths_), 51 Bootstrap::convert_patch_paths_),
54 INIT_LIBRARY(ObjectStore::kCollection, 52 INIT_LIBRARY(ObjectStore::kCollection,
55 collection, 53 collection,
56 Bootstrap::collection_source_paths_, 54 Bootstrap::collection_source_paths_,
57 Bootstrap::collection_patch_paths_), 55 Bootstrap::collection_patch_paths_),
58 INIT_LIBRARY(ObjectStore::kDeveloper, 56 INIT_LIBRARY(ObjectStore::kDeveloper,
59 developer, 57 developer,
60 Bootstrap::developer_source_paths_, 58 Bootstrap::developer_source_paths_,
61 Bootstrap::developer_patch_paths_), 59 Bootstrap::developer_patch_paths_),
62 INIT_LIBRARY(ObjectStore::kInternal, 60 INIT_LIBRARY(ObjectStore::kInternal,
63 _internal, 61 _internal,
64 Bootstrap::_internal_source_paths_, 62 Bootstrap::_internal_source_paths_,
65 Bootstrap::_internal_patch_paths_), 63 Bootstrap::_internal_patch_paths_),
66 INIT_LIBRARY(ObjectStore::kIsolate, 64 INIT_LIBRARY(ObjectStore::kIsolate,
67 isolate, 65 isolate,
68 Bootstrap::isolate_source_paths_, 66 Bootstrap::isolate_source_paths_,
69 Bootstrap::isolate_patch_paths_), 67 Bootstrap::isolate_patch_paths_),
70 INIT_LIBRARY(ObjectStore::kMath, 68 INIT_LIBRARY(ObjectStore::kMath,
71 math, 69 math,
72 Bootstrap::math_source_paths_, 70 Bootstrap::math_source_paths_,
73 Bootstrap::math_patch_paths_), 71 Bootstrap::math_patch_paths_),
74 INIT_LIBRARY(ObjectStore::kMirrors, 72 INIT_LIBRARY(ObjectStore::kMirrors,
75 mirrors, 73 mirrors,
76 Bootstrap::mirrors_source_paths_, 74 Bootstrap::mirrors_source_paths_,
77 Bootstrap::mirrors_patch_paths_), 75 Bootstrap::mirrors_patch_paths_),
78 INIT_LIBRARY(ObjectStore::kProfiler, 76 INIT_LIBRARY(ObjectStore::kProfiler,
79 profiler, 77 profiler,
80 Bootstrap::profiler_source_paths_, 78 Bootstrap::profiler_source_paths_,
81 NULL), 79 NULL),
82 INIT_LIBRARY(ObjectStore::kTypedData, 80 INIT_LIBRARY(ObjectStore::kTypedData,
83 typed_data, 81 typed_data,
84 Bootstrap::typed_data_source_paths_, 82 Bootstrap::typed_data_source_paths_,
85 NULL), 83 NULL),
86 INIT_LIBRARY(ObjectStore::kVMService, 84 INIT_LIBRARY(ObjectStore::kVMService,
87 _vmservice, 85 _vmservice,
88 Bootstrap::_vmservice_source_paths_, 86 Bootstrap::_vmservice_source_paths_,
89 Bootstrap::_vmservice_patch_paths_), 87 Bootstrap::_vmservice_patch_paths_),
90 { ObjectStore::kNone, NULL, NULL, NULL, NULL } 88 {ObjectStore::kNone, NULL, NULL, NULL, NULL}};
91 };
92 89
93 90
94 static RawString* GetLibrarySource(const Library& lib, 91 static RawString* GetLibrarySource(const Library& lib,
95 const String& uri, 92 const String& uri,
96 bool patch) { 93 bool patch) {
97 // First check if this is a valid bootstrap library and find it's index 94 // First check if this is a valid bootstrap library and find it's index
98 // in the 'bootstrap_libraries' table above. 95 // in the 'bootstrap_libraries' table above.
99 intptr_t index; 96 intptr_t index;
100 const String& lib_uri = String::Handle(lib.url()); 97 const String& lib_uri = String::Handle(lib.url());
101 for (index = 0; 98 for (index = 0; bootstrap_libraries[index].index_ != ObjectStore::kNone;
102 bootstrap_libraries[index].index_ != ObjectStore::kNone;
103 ++index) { 99 ++index) {
104 if (lib_uri.Equals(bootstrap_libraries[index].uri_)) { 100 if (lib_uri.Equals(bootstrap_libraries[index].uri_)) {
105 break; 101 break;
106 } 102 }
107 } 103 }
108 if (bootstrap_libraries[index].index_ == ObjectStore::kNone) { 104 if (bootstrap_libraries[index].index_ == ObjectStore::kNone) {
109 return String::null(); // Library is not a bootstrap library. 105 return String::null(); // Library is not a bootstrap library.
110 } 106 }
111 107
112 // Try to read the source using the path specified for the uri. 108 // Try to read the source using the path specified for the uri.
113 const char** source_paths = patch ? 109 const char** source_paths = patch ? bootstrap_libraries[index].patch_paths_
114 bootstrap_libraries[index].patch_paths_ : 110 : bootstrap_libraries[index].source_paths_;
115 bootstrap_libraries[index].source_paths_;
116 if (source_paths == NULL) { 111 if (source_paths == NULL) {
117 return String::null(); // No path mapping information exists for library. 112 return String::null(); // No path mapping information exists for library.
118 } 113 }
119 const char* source_path = NULL; 114 const char* source_path = NULL;
120 const char* source_data = NULL; 115 const char* source_data = NULL;
121 for (intptr_t i = 0; source_paths[i] != NULL; i += kPathsEntryLength) { 116 for (intptr_t i = 0; source_paths[i] != NULL; i += kPathsEntryLength) {
122 if (uri.Equals(source_paths[i + kPathsUriOffset])) { 117 if (uri.Equals(source_paths[i + kPathsUriOffset])) {
123 source_path = source_paths[i + kPathsFileOffset]; 118 source_path = source_paths[i + kPathsFileOffset];
124 source_data = source_paths[i + kPathsSourceOffset]; 119 source_data = source_paths[i + kPathsSourceOffset];
125 break; 120 break;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 } 169 }
175 } 170 }
176 return error.raw(); 171 return error.raw();
177 } 172 }
178 173
179 174
180 static Dart_Handle LoadPartSource(Thread* thread, 175 static Dart_Handle LoadPartSource(Thread* thread,
181 const Library& lib, 176 const Library& lib,
182 const String& uri) { 177 const String& uri) {
183 Zone* zone = thread->zone(); 178 Zone* zone = thread->zone();
184 const String& part_source = String::Handle( 179 const String& part_source =
185 zone, GetLibrarySource(lib, uri, false)); 180 String::Handle(zone, GetLibrarySource(lib, uri, false));
186 const String& lib_uri = String::Handle(zone, lib.url()); 181 const String& lib_uri = String::Handle(zone, lib.url());
187 if (part_source.IsNull()) { 182 if (part_source.IsNull()) {
188 return Api::NewError("Unable to read part file '%s' of library '%s'", 183 return Api::NewError("Unable to read part file '%s' of library '%s'",
189 uri.ToCString(), lib_uri.ToCString()); 184 uri.ToCString(), lib_uri.ToCString());
190 } 185 }
191 186
192 // Prepend the library URI to form a unique script URI for the part. 187 // Prepend the library URI to form a unique script URI for the part.
193 const Array& strings = Array::Handle(zone, Array::New(3)); 188 const Array& strings = Array::Handle(zone, Array::New(3));
194 strings.SetAt(0, lib_uri); 189 strings.SetAt(0, lib_uri);
195 strings.SetAt(1, Symbols::Slash()); 190 strings.SetAt(1, Symbols::Slash());
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 Error& error = Error::Handle(zone); 280 Error& error = Error::Handle(zone);
286 Dart_LibraryTagHandler saved_tag_handler = isolate->library_tag_handler(); 281 Dart_LibraryTagHandler saved_tag_handler = isolate->library_tag_handler();
287 282
288 // Set the library tag handler for the isolate to the bootstrap 283 // Set the library tag handler for the isolate to the bootstrap
289 // library tag handler so that we can load all the bootstrap libraries. 284 // library tag handler so that we can load all the bootstrap libraries.
290 isolate->set_library_tag_handler(BootstrapLibraryTagHandler); 285 isolate->set_library_tag_handler(BootstrapLibraryTagHandler);
291 286
292 HANDLESCOPE(thread); 287 HANDLESCOPE(thread);
293 288
294 // Create library objects for all the bootstrap libraries. 289 // Create library objects for all the bootstrap libraries.
295 for (intptr_t i = 0; 290 for (intptr_t i = 0; bootstrap_libraries[i].index_ != ObjectStore::kNone;
296 bootstrap_libraries[i].index_ != ObjectStore::kNone;
297 ++i) { 291 ++i) {
298 #ifdef PRODUCT 292 #ifdef PRODUCT
299 if (bootstrap_libraries[i].index_ == ObjectStore::kMirrors) { 293 if (bootstrap_libraries[i].index_ == ObjectStore::kMirrors) {
300 continue; 294 continue;
301 } 295 }
302 #endif // !PRODUCT 296 #endif // !PRODUCT
303 uri = Symbols::New(thread, bootstrap_libraries[i].uri_); 297 uri = Symbols::New(thread, bootstrap_libraries[i].uri_);
304 lib = Library::LookupLibrary(thread, uri); 298 lib = Library::LookupLibrary(thread, uri);
305 if (lib.IsNull()) { 299 if (lib.IsNull()) {
306 lib = Library::NewLibraryHelper(uri, false); 300 lib = Library::NewLibraryHelper(uri, false);
307 lib.SetLoadRequested(); 301 lib.SetLoadRequested();
308 lib.Register(thread); 302 lib.Register(thread);
309 } 303 }
310 isolate->object_store()->set_bootstrap_library( 304 isolate->object_store()->set_bootstrap_library(
311 bootstrap_libraries[i].index_, lib); 305 bootstrap_libraries[i].index_, lib);
312 } 306 }
313 307
314 // Load, compile and patch bootstrap libraries. 308 // Load, compile and patch bootstrap libraries.
315 for (intptr_t i = 0; 309 for (intptr_t i = 0; bootstrap_libraries[i].index_ != ObjectStore::kNone;
316 bootstrap_libraries[i].index_ != ObjectStore::kNone;
317 ++i) { 310 ++i) {
318 #ifdef PRODUCT 311 #ifdef PRODUCT
319 if (bootstrap_libraries[i].index_ == ObjectStore::kMirrors) { 312 if (bootstrap_libraries[i].index_ == ObjectStore::kMirrors) {
320 continue; 313 continue;
321 } 314 }
322 #endif // PRODUCT 315 #endif // PRODUCT
323 uri = Symbols::New(thread, bootstrap_libraries[i].uri_); 316 uri = Symbols::New(thread, bootstrap_libraries[i].uri_);
324 lib = Library::LookupLibrary(thread, uri); 317 lib = Library::LookupLibrary(thread, uri);
325 ASSERT(!lib.IsNull()); 318 ASSERT(!lib.IsNull());
326 source = GetLibrarySource(lib, uri, false); 319 source = GetLibrarySource(lib, uri, false);
327 if (source.IsNull()) { 320 if (source.IsNull()) {
328 const String& message = String::Handle( 321 const String& message = String::Handle(String::NewFormatted(
329 String::NewFormatted("Unable to find dart source for %s", 322 "Unable to find dart source for %s", uri.ToCString()));
330 uri.ToCString()));
331 error ^= ApiError::New(message); 323 error ^= ApiError::New(message);
332 break; 324 break;
333 } 325 }
334 script = Script::New(uri, source, RawScript::kLibraryTag); 326 script = Script::New(uri, source, RawScript::kLibraryTag);
335 error = Compile(lib, script); 327 error = Compile(lib, script);
336 if (!error.IsNull()) { 328 if (!error.IsNull()) {
337 break; 329 break;
338 } 330 }
339 // If a patch exists, load and patch the script. 331 // If a patch exists, load and patch the script.
340 if (bootstrap_libraries[i].patch_paths_ != NULL) { 332 if (bootstrap_libraries[i].patch_paths_ != NULL) {
341 patch_uri = Symbols::New(thread, bootstrap_libraries[i].patch_uri_); 333 patch_uri = Symbols::New(thread, bootstrap_libraries[i].patch_uri_);
342 error = LoadPatchFiles(zone, 334 error = LoadPatchFiles(zone, lib, patch_uri,
343 lib,
344 patch_uri,
345 bootstrap_libraries[i].patch_paths_); 335 bootstrap_libraries[i].patch_paths_);
346 if (!error.IsNull()) { 336 if (!error.IsNull()) {
347 break; 337 break;
348 } 338 }
349 } 339 }
350 } 340 }
351 if (error.IsNull()) { 341 if (error.IsNull()) {
352 SetupNativeResolver(); 342 SetupNativeResolver();
353 ClassFinalizer::ProcessPendingClasses(); 343 ClassFinalizer::ProcessPendingClasses();
354 344
355 // Eagerly compile the _Closure class as it is the class of all closure 345 // Eagerly compile the _Closure class as it is the class of all closure
356 // instances. This allows us to just finalize function types 346 // instances. This allows us to just finalize function types
357 // without going through the hoops of trying to compile their scope class. 347 // without going through the hoops of trying to compile their scope class.
358 Class& cls = 348 Class& cls = Class::Handle(zone, isolate->object_store()->closure_class());
359 Class::Handle(zone, isolate->object_store()->closure_class());
360 Compiler::CompileClass(cls); 349 Compiler::CompileClass(cls);
361 // Eagerly compile Bool class, bool constants are used from within compiler. 350 // Eagerly compile Bool class, bool constants are used from within compiler.
362 cls = isolate->object_store()->bool_class(); 351 cls = isolate->object_store()->bool_class();
363 Compiler::CompileClass(cls); 352 Compiler::CompileClass(cls);
364 } 353 }
365 354
366 // Restore the library tag handler for the isolate. 355 // Restore the library tag handler for the isolate.
367 isolate->set_library_tag_handler(saved_tag_handler); 356 isolate->set_library_tag_handler(saved_tag_handler);
368 357
369 return error.raw(); 358 return error.raw();
370 } 359 }
371 360
372 } // namespace dart 361 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/boolfield.h ('k') | runtime/vm/bootstrap_natives.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698