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

Side by Side Diff: bin/builtin.cc

Issue 10388242: Minor restructure some of the builtin library processing code (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 6 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 <stdio.h> 5 #include <stdio.h>
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 8
9 #include "bin/builtin.h" 9 #include "bin/builtin.h"
10 #include "bin/dartutils.h" 10 #include "bin/dartutils.h"
11 11
12
13 Builtin::builtin_lib_props Builtin::builtin_libraries_[] = {
14 /* url_ source_ has_natives_ */
15 { DartUtils::kBuiltinLibURL, builtin_source_, true },
16 { DartUtils::kJsonLibURL, json_source_, false },
17 { DartUtils::kUriLibURL, uri_source_, false },
18 { DartUtils::kCryptoLibURL, crypto_source_, false },
19 { DartUtils::kIOLibURL, io_source_, true },
20 { DartUtils::kUtfLibURL, utf_source_, false }
21 };
22
23
12 static void ImportBuiltinLibIntoLib( 24 static void ImportBuiltinLibIntoLib(
13 const char* liburl, Dart_Handle builtin_lib) { 25 const char* liburl, Dart_Handle builtin_lib) {
14 Dart_Handle url = Dart_NewString(liburl); 26 Dart_Handle url = Dart_NewString(liburl);
15 Dart_Handle lib = Dart_LookupLibrary(url); 27 Dart_Handle lib = Dart_LookupLibrary(url);
16 DART_CHECK_VALID(lib); 28 DART_CHECK_VALID(lib);
17 DART_CHECK_VALID(Dart_LibraryImportLibrary(lib, builtin_lib)); 29 DART_CHECK_VALID(Dart_LibraryImportLibrary(lib, builtin_lib));
18 } 30 }
19 31
20 32
21 Dart_Handle Builtin::Source(BuiltinLibraryId id) { 33 Dart_Handle Builtin::Source(BuiltinLibraryId id) {
22 Dart_Handle source; 34 ASSERT(id >= kBuiltinLibrary && id < kInvalidLibrary);
hausner 2012/05/31 15:57:11 This code assumes that kBuiltinLibrary is the firs
siva 2012/05/31 20:57:19 I have added an assertion to ensure that the size
23 switch (id) { 35 return Dart_NewString(builtin_libraries_[id].source_);
24 case kBuiltinLibrary:
25 source = Dart_NewString(Builtin::builtin_source_);
26 break;
27 case kCryptoLibrary:
28 source = Dart_NewString(Builtin::crypto_source_);
29 break;
30 case kIOLibrary:
31 source = Dart_NewString(Builtin::io_source_);
32 break;
33 case kJsonLibrary:
34 source = Dart_NewString(Builtin::json_source_);
35 break;
36 case kUriLibrary:
37 source = Dart_NewString(Builtin::uri_source_);
38 break;
39 case kUtfLibrary:
40 source = Dart_NewString(Builtin::utf_source_);
41 break;
42 default:
43 return Dart_Error("Unknown builtin source requested.");
44 }
45 return source;
46 } 36 }
47 37
48 38
49 void Builtin::SetupLibrary(Dart_Handle library, BuiltinLibraryId id) { 39 void Builtin::SetupLibrary(Dart_Handle library, BuiltinLibraryId id) {
50 if ((id == kCryptoLibrary) || 40 ASSERT(id >= kBuiltinLibrary && id < kInvalidLibrary);
hausner 2012/05/31 15:57:11 ditto.
siva 2012/05/31 20:57:19 Ditto. On 2012/05/31 15:57:11, hausner wrote:
51 (id == kJsonLibrary) || 41 if (builtin_libraries_[id].has_natives_) {
52 (id == kUriLibrary) || 42 // Setup the native resolver for built in library functions.
53 (id == kUtfLibrary)) { 43 DART_CHECK_VALID(Dart_SetNativeResolver(library, NativeLookup));
54 // No native resolver for these pure Dart libraries. 44 }
55 return; 45 if (id == kBuiltinLibrary) {
56 } else if (id == kBuiltinLibrary) {
57 // Import the builtin library into the core and isolate libraries. 46 // Import the builtin library into the core and isolate libraries.
58 ImportBuiltinLibIntoLib(DartUtils::kCoreLibURL, library); 47 ImportBuiltinLibIntoLib(DartUtils::kCoreLibURL, library);
59 ImportBuiltinLibIntoLib(DartUtils::kCoreImplLibURL, library); 48 ImportBuiltinLibIntoLib(DartUtils::kCoreImplLibURL, library);
60 ImportBuiltinLibIntoLib(DartUtils::kIsolateLibURL, library); 49 ImportBuiltinLibIntoLib(DartUtils::kIsolateLibURL, library);
61 } 50 }
62 // Setup the native resolver for built in library functions.
63 DART_CHECK_VALID(Dart_SetNativeResolver(library, NativeLookup));
64 } 51 }
65 52
66 53
67 Dart_Handle Builtin::LoadLibrary(BuiltinLibraryId id) { 54 Dart_Handle Builtin::LoadLibrary(BuiltinLibraryId id) {
68 Dart_Handle url; 55 ASSERT(id >= kBuiltinLibrary && id < kInvalidLibrary);
hausner 2012/05/31 15:57:11 ditto.
siva 2012/05/31 20:57:19 Ditto. On 2012/05/31 15:57:11, hausner wrote:
69 switch (id) { 56 Dart_Handle url = Dart_NewString(builtin_libraries_[id].url_);
70 case kBuiltinLibrary:
71 url = Dart_NewString(DartUtils::kBuiltinLibURL);
72 break;
73 case kCryptoLibrary:
74 url = Dart_NewString(DartUtils::kCryptoLibURL);
75 break;
76 case kIOLibrary:
77 url = Dart_NewString(DartUtils::kIOLibURL);
78 break;
79 case kJsonLibrary:
80 url = Dart_NewString(DartUtils::kJsonLibURL);
81 break;
82 case kUriLibrary:
83 url = Dart_NewString(DartUtils::kUriLibURL);
84 break;
85 case kUtfLibrary:
86 url = Dart_NewString(DartUtils::kUtfLibURL);
87 break;
88 default:
89 return Dart_Error("Unknown builtin library requested.");
90 }
91 Dart_Handle library = Dart_LookupLibrary(url); 57 Dart_Handle library = Dart_LookupLibrary(url);
92 if (Dart_IsError(library)) { 58 if (Dart_IsError(library)) {
93 library = Dart_LoadLibrary(url, Source(id)); 59 library = Dart_LoadLibrary(url, Source(id));
94 if (!Dart_IsError(library)) { 60 if (!Dart_IsError(library)) {
95 SetupLibrary(library, id); 61 SetupLibrary(library, id);
96 } 62 }
97 } 63 }
98 DART_CHECK_VALID(library); 64 DART_CHECK_VALID(library);
99 return library; 65 return library;
100 } 66 }
101 67
102 68
103 void Builtin::ImportLibrary(Dart_Handle library, BuiltinLibraryId id) { 69 void Builtin::ImportLibrary(Dart_Handle library, BuiltinLibraryId id) {
104 Dart_Handle imported_library = LoadLibrary(id); 70 Dart_Handle imported_library = LoadLibrary(id);
105 // Import the library into current library. 71 // Import the library into current library.
106 DART_CHECK_VALID(Dart_LibraryImportLibrary(library, imported_library)); 72 DART_CHECK_VALID(Dart_LibraryImportLibrary(library, imported_library));
107 } 73 }
OLDNEW
« no previous file with comments | « bin/builtin.h ('k') | bin/builtin_nolib.cc » ('j') | bin/builtin_nolib.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698