mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 02:37:53 +00:00
The formatter struggles a bit with these files.
BUG= R=johnmccutchan@google.com Review-Url: https://codereview.chromium.org/2765523003 .
This commit is contained in:
parent
2cd2ffa949
commit
a129931cda
|
@ -70,10 +70,8 @@ class IsolateLoaderState extends IsolateEmbedderData {
|
|||
|
||||
SendPort sp;
|
||||
|
||||
void init(String packageRootFlag,
|
||||
String packagesConfigFlag,
|
||||
String workingDirectory,
|
||||
String rootScript) {
|
||||
void init(String packageRootFlag, String packagesConfigFlag,
|
||||
String workingDirectory, String rootScript) {
|
||||
// _workingDirectory must be set first.
|
||||
_workingDirectory = new Uri.directory(workingDirectory);
|
||||
if (rootScript != null) {
|
||||
|
@ -107,9 +105,10 @@ class IsolateLoaderState extends IsolateEmbedderData {
|
|||
|
||||
// Packages are either resolved looking up in a map or resolved from within a
|
||||
// package root.
|
||||
bool get _packagesReady => (_packageRoot != null) ||
|
||||
(_packageMap != null) ||
|
||||
(_packageError != null);
|
||||
bool get _packagesReady =>
|
||||
(_packageRoot != null) ||
|
||||
(_packageMap != null) ||
|
||||
(_packageError != null);
|
||||
|
||||
// Error string set if there was an error resolving package configuration.
|
||||
// For example not finding a .packages file or packages/ directory, malformed
|
||||
|
@ -135,6 +134,7 @@ class IsolateLoaderState extends IsolateEmbedderData {
|
|||
void enqueueFileRequest(FileRequest fr) {
|
||||
_fileRequestQueue.add(fr);
|
||||
}
|
||||
|
||||
FileRequest dequeueFileRequest() {
|
||||
if (_fileRequestQueue.length == 0) {
|
||||
return null;
|
||||
|
@ -203,14 +203,14 @@ class IsolateLoaderState extends IsolateEmbedderData {
|
|||
var wrong = 'package://$path';
|
||||
|
||||
throw "URIs using the 'package:' scheme should look like "
|
||||
"'$right', not '$wrong'.";
|
||||
"'$right', not '$wrong'.";
|
||||
}
|
||||
|
||||
var packageNameEnd = uri.path.indexOf('/');
|
||||
if (packageNameEnd == 0) {
|
||||
// Package URIs must have a non-empty package name (not start with "/").
|
||||
throw "URIS using the 'package:' scheme should look like "
|
||||
"'package:packageName${uri.path}', not 'package:${uri.path}'";
|
||||
"'package:packageName${uri.path}', not 'package:${uri.path}'";
|
||||
}
|
||||
if (_traceLoading) {
|
||||
_log('Resolving package with uri path: ${uri.path}');
|
||||
|
@ -228,7 +228,7 @@ class IsolateLoaderState extends IsolateEmbedderData {
|
|||
// Package URIs must have a path after the package name, even if it's
|
||||
// just "/".
|
||||
throw "URIS using the 'package:' scheme should look like "
|
||||
"'package:${uri.path}/', not 'package:${uri.path}'";
|
||||
"'package:${uri.path}/', not 'package:${uri.path}'";
|
||||
}
|
||||
var packageName = uri.path.substring(0, packageNameEnd);
|
||||
var mapping = _packageMap[packageName];
|
||||
|
@ -263,16 +263,10 @@ class IsolateLoaderState extends IsolateEmbedderData {
|
|||
|
||||
if (packageConfig != null) {
|
||||
// Explicitly specified .packages path.
|
||||
_handlePackagesRequest(sp,
|
||||
_traceLoading,
|
||||
-2,
|
||||
packageConfig);
|
||||
_handlePackagesRequest(sp, _traceLoading, -2, packageConfig);
|
||||
} else {
|
||||
// Search for .packages or packages/ starting at the root script.
|
||||
_handlePackagesRequest(sp,
|
||||
_traceLoading,
|
||||
-1,
|
||||
_rootScript);
|
||||
_handlePackagesRequest(sp, _traceLoading, -1, _rootScript);
|
||||
}
|
||||
|
||||
if (_traceLoading) {
|
||||
|
@ -308,9 +302,9 @@ class IsolateLoaderState extends IsolateEmbedderData {
|
|||
assert(msg[1] == null);
|
||||
_packageConfig = Uri.parse(msg[0]);
|
||||
_packageMap = new Map<String, Uri>();
|
||||
for (var i = 2; i < msg.length; i+=2) {
|
||||
for (var i = 2; i < msg.length; i += 2) {
|
||||
// TODO(iposva): Complain about duplicate entries.
|
||||
_packageMap[msg[i]] = Uri.parse(msg[i+1]);
|
||||
_packageMap[msg[i]] = Uri.parse(msg[i + 1]);
|
||||
}
|
||||
if (_traceLoading) {
|
||||
_log("Setup package map: $_packageMap");
|
||||
|
@ -334,7 +328,6 @@ class IsolateLoaderState extends IsolateEmbedderData {
|
|||
// finish loading.
|
||||
_pendingPackageLoads = [];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
_log(msg) {
|
||||
|
@ -344,12 +337,8 @@ _log(msg) {
|
|||
var _httpClient;
|
||||
|
||||
// Send a response to the requesting isolate.
|
||||
void _sendResourceResponse(SendPort sp,
|
||||
int tag,
|
||||
Uri uri,
|
||||
Uri resolvedUri,
|
||||
String libraryUrl,
|
||||
dynamic data) {
|
||||
void _sendResourceResponse(SendPort sp, int tag, Uri uri, Uri resolvedUri,
|
||||
String libraryUrl, dynamic data) {
|
||||
assert((data is List<int>) || (data is String));
|
||||
var msg = new List(5);
|
||||
if (data is String) {
|
||||
|
@ -370,10 +359,8 @@ void _sendResourceResponse(SendPort sp,
|
|||
}
|
||||
|
||||
// Send a response to the requesting isolate.
|
||||
void _sendExtensionImportResponse(SendPort sp,
|
||||
Uri uri,
|
||||
String libraryUrl,
|
||||
String resolvedUri) {
|
||||
void _sendExtensionImportResponse(
|
||||
SendPort sp, Uri uri, String libraryUrl, String resolvedUri) {
|
||||
var msg = new List(5);
|
||||
int tag = _Dart_kImportExtension;
|
||||
if (resolvedUri == null) {
|
||||
|
@ -389,56 +376,44 @@ void _sendExtensionImportResponse(SendPort sp,
|
|||
sp.send(msg);
|
||||
}
|
||||
|
||||
void _loadHttp(SendPort sp,
|
||||
int tag,
|
||||
Uri uri,
|
||||
Uri resolvedUri,
|
||||
String libraryUrl) {
|
||||
void _loadHttp(
|
||||
SendPort sp, int tag, Uri uri, Uri resolvedUri, String libraryUrl) {
|
||||
if (_httpClient == null) {
|
||||
_httpClient = new HttpClient()..maxConnectionsPerHost = 6;
|
||||
}
|
||||
_httpClient.getUrl(resolvedUri)
|
||||
.then((HttpClientRequest request) => request.close())
|
||||
.then((HttpClientResponse response) {
|
||||
var builder = new BytesBuilder(copy: false);
|
||||
response.listen(
|
||||
builder.add,
|
||||
onDone: () {
|
||||
if (response.statusCode != 200) {
|
||||
var msg = "Failure getting $resolvedUri:\n"
|
||||
" ${response.statusCode} ${response.reasonPhrase}";
|
||||
_sendResourceResponse(sp, tag, uri, resolvedUri, libraryUrl, msg);
|
||||
} else {
|
||||
_sendResourceResponse(sp, tag, uri, resolvedUri, libraryUrl,
|
||||
builder.takeBytes());
|
||||
}
|
||||
},
|
||||
onError: (e) {
|
||||
_sendResourceResponse(
|
||||
sp, tag, uri, resolvedUri, libraryUrl, e.toString());
|
||||
});
|
||||
})
|
||||
.catchError((e) {
|
||||
_httpClient
|
||||
.getUrl(resolvedUri)
|
||||
.then((HttpClientRequest request) => request.close())
|
||||
.then((HttpClientResponse response) {
|
||||
var builder = new BytesBuilder(copy: false);
|
||||
response.listen(builder.add, onDone: () {
|
||||
if (response.statusCode != 200) {
|
||||
var msg = "Failure getting $resolvedUri:\n"
|
||||
" ${response.statusCode} ${response.reasonPhrase}";
|
||||
_sendResourceResponse(sp, tag, uri, resolvedUri, libraryUrl, msg);
|
||||
} else {
|
||||
_sendResourceResponse(
|
||||
sp, tag, uri, resolvedUri, libraryUrl, builder.takeBytes());
|
||||
}
|
||||
}, onError: (e) {
|
||||
_sendResourceResponse(
|
||||
sp, tag, uri, resolvedUri, libraryUrl, e.toString());
|
||||
sp, tag, uri, resolvedUri, libraryUrl, e.toString());
|
||||
});
|
||||
}).catchError((e) {
|
||||
_sendResourceResponse(sp, tag, uri, resolvedUri, libraryUrl, e.toString());
|
||||
});
|
||||
// It's just here to push an event on the event loop so that we invoke the
|
||||
// scheduled microtasks.
|
||||
Timer.run(() {});
|
||||
}
|
||||
|
||||
void _loadFile(IsolateLoaderState loaderState,
|
||||
SendPort sp,
|
||||
int tag,
|
||||
Uri uri,
|
||||
Uri resolvedUri,
|
||||
String libraryUrl) {
|
||||
void _loadFile(IsolateLoaderState loaderState, SendPort sp, int tag, Uri uri,
|
||||
Uri resolvedUri, String libraryUrl) {
|
||||
var path = resolvedUri.toFilePath();
|
||||
var sourceFile = new File(path);
|
||||
sourceFile.readAsBytes().then((data) {
|
||||
_sendResourceResponse(sp, tag, uri, resolvedUri, libraryUrl, data);
|
||||
},
|
||||
onError: (e) {
|
||||
}, onError: (e) {
|
||||
_sendResourceResponse(sp, tag, uri, resolvedUri, libraryUrl, e.toString());
|
||||
}).whenComplete(() {
|
||||
loaderState.currentFileRequests--;
|
||||
|
@ -454,20 +429,15 @@ void _loadFile(IsolateLoaderState loaderState,
|
|||
});
|
||||
}
|
||||
|
||||
void _loadDataUri(SendPort sp,
|
||||
int tag,
|
||||
Uri uri,
|
||||
Uri resolvedUri,
|
||||
String libraryUrl) {
|
||||
void _loadDataUri(
|
||||
SendPort sp, int tag, Uri uri, Uri resolvedUri, String libraryUrl) {
|
||||
try {
|
||||
var mime = uri.data.mimeType;
|
||||
if ((mime != "application/dart") &&
|
||||
(mime != "text/plain")) {
|
||||
if ((mime != "application/dart") && (mime != "text/plain")) {
|
||||
throw "MIME-type must be application/dart or text/plain: $mime given.";
|
||||
}
|
||||
var charset = uri.data.charset;
|
||||
if ((charset != "utf-8") &&
|
||||
(charset != "US-ASCII")) {
|
||||
if ((charset != "utf-8") && (charset != "US-ASCII")) {
|
||||
// The C++ portion of the embedder assumes UTF-8.
|
||||
throw "Only utf-8 or US-ASCII encodings are supported: $charset given.";
|
||||
}
|
||||
|
@ -475,19 +445,14 @@ void _loadDataUri(SendPort sp,
|
|||
sp, tag, uri, resolvedUri, libraryUrl, uri.data.contentAsBytes());
|
||||
} catch (e) {
|
||||
_sendResourceResponse(sp, tag, uri, resolvedUri, libraryUrl,
|
||||
"Invalid data uri ($uri):\n $e");
|
||||
"Invalid data uri ($uri):\n $e");
|
||||
}
|
||||
}
|
||||
|
||||
// Loading a package URI needs to first map the package name to a loadable
|
||||
// URI.
|
||||
_loadPackage(IsolateLoaderState loaderState,
|
||||
SendPort sp,
|
||||
bool traceLoading,
|
||||
int tag,
|
||||
Uri uri,
|
||||
Uri resolvedUri,
|
||||
String libraryUrl) {
|
||||
_loadPackage(IsolateLoaderState loaderState, SendPort sp, bool traceLoading,
|
||||
int tag, Uri uri, Uri resolvedUri, String libraryUrl) {
|
||||
if (loaderState._packagesReady) {
|
||||
var resolvedUri;
|
||||
try {
|
||||
|
@ -497,22 +462,13 @@ _loadPackage(IsolateLoaderState loaderState,
|
|||
_log("Exception ($e) when resolving package URI: $uri");
|
||||
}
|
||||
// Report error.
|
||||
_sendResourceResponse(sp,
|
||||
tag,
|
||||
uri,
|
||||
resolvedUri,
|
||||
libraryUrl,
|
||||
e.toString());
|
||||
_sendResourceResponse(
|
||||
sp, tag, uri, resolvedUri, libraryUrl, e.toString());
|
||||
return;
|
||||
}
|
||||
// Recursively call with the new resolved uri.
|
||||
_handleResourceRequest(loaderState,
|
||||
sp,
|
||||
traceLoading,
|
||||
tag,
|
||||
uri,
|
||||
resolvedUri,
|
||||
libraryUrl);
|
||||
_handleResourceRequest(
|
||||
loaderState, sp, traceLoading, tag, uri, resolvedUri, libraryUrl);
|
||||
} else {
|
||||
if (loaderState._pendingPackageLoads.isEmpty) {
|
||||
// Package resolution has not been setup yet, and this is the first
|
||||
|
@ -522,30 +478,20 @@ _loadPackage(IsolateLoaderState loaderState,
|
|||
// Register the action of loading this package once the package resolution
|
||||
// is ready.
|
||||
loaderState._pendingPackageLoads.add(() {
|
||||
_handleResourceRequest(loaderState,
|
||||
sp,
|
||||
traceLoading,
|
||||
tag,
|
||||
uri,
|
||||
uri,
|
||||
libraryUrl);
|
||||
_handleResourceRequest(
|
||||
loaderState, sp, traceLoading, tag, uri, uri, libraryUrl);
|
||||
});
|
||||
if (traceLoading) {
|
||||
_log("Pending package load of '$uri': "
|
||||
"${loaderState._pendingPackageLoads.length} pending");
|
||||
"${loaderState._pendingPackageLoads.length} pending");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(johnmccutchan): This and most other top level functions in this file
|
||||
// should be turned into methods on the IsolateLoaderState class.
|
||||
_handleResourceRequest(IsolateLoaderState loaderState,
|
||||
SendPort sp,
|
||||
bool traceLoading,
|
||||
int tag,
|
||||
Uri uri,
|
||||
Uri resolvedUri,
|
||||
String libraryUrl) {
|
||||
_handleResourceRequest(IsolateLoaderState loaderState, SendPort sp,
|
||||
bool traceLoading, int tag, Uri uri, Uri resolvedUri, String libraryUrl) {
|
||||
if (resolvedUri.scheme == '' || resolvedUri.scheme == 'file') {
|
||||
if (loaderState.shouldIssueFileRequest) {
|
||||
_loadFile(loaderState, sp, tag, uri, resolvedUri, libraryUrl);
|
||||
|
@ -555,69 +501,136 @@ _handleResourceRequest(IsolateLoaderState loaderState,
|
|||
loaderState.enqueueFileRequest(fr);
|
||||
}
|
||||
} else if ((resolvedUri.scheme == 'http') ||
|
||||
(resolvedUri.scheme == 'https')) {
|
||||
(resolvedUri.scheme == 'https')) {
|
||||
_loadHttp(sp, tag, uri, resolvedUri, libraryUrl);
|
||||
} else if ((resolvedUri.scheme == 'data')) {
|
||||
_loadDataUri(sp, tag, uri, resolvedUri, libraryUrl);
|
||||
} else if ((resolvedUri.scheme == 'package')) {
|
||||
_loadPackage(loaderState,
|
||||
sp,
|
||||
traceLoading,
|
||||
tag,
|
||||
uri,
|
||||
resolvedUri,
|
||||
libraryUrl);
|
||||
_loadPackage(
|
||||
loaderState, sp, traceLoading, tag, uri, resolvedUri, libraryUrl);
|
||||
} else {
|
||||
_sendResourceResponse(sp, tag,
|
||||
uri,
|
||||
resolvedUri,
|
||||
libraryUrl,
|
||||
'Unknown scheme (${resolvedUri.scheme}) for '
|
||||
'$resolvedUri');
|
||||
_sendResourceResponse(
|
||||
sp,
|
||||
tag,
|
||||
uri,
|
||||
resolvedUri,
|
||||
libraryUrl,
|
||||
'Unknown scheme (${resolvedUri.scheme}) for '
|
||||
'$resolvedUri');
|
||||
}
|
||||
}
|
||||
|
||||
// Handling of packages requests. Finding and parsing of .packages file or
|
||||
// packages/ directories.
|
||||
const _LF = 0x0A;
|
||||
const _CR = 0x0D;
|
||||
const _LF = 0x0A;
|
||||
const _CR = 0x0D;
|
||||
const _SPACE = 0x20;
|
||||
const _HASH = 0x23;
|
||||
const _DOT = 0x2E;
|
||||
const _HASH = 0x23;
|
||||
const _DOT = 0x2E;
|
||||
const _COLON = 0x3A;
|
||||
const _DEL = 0x7F;
|
||||
const _DEL = 0x7F;
|
||||
|
||||
const _invalidPackageNameChars = const [
|
||||
// space ! " # $ % & '
|
||||
true , false, true , true , false, true , false, false,
|
||||
// ( ) * + , - . /
|
||||
false, false, false, false, false, false, false, true ,
|
||||
// 0 1 2 3 4 5 6 7
|
||||
false, false, false, false, false, false, false, false,
|
||||
// 8 9 : ; < = > ?
|
||||
false, false, true , false, true , false, true , true ,
|
||||
// @ A B C D E F G
|
||||
false, false, false, false, false, false, false, false,
|
||||
// H I J K L M N O
|
||||
false, false, false, false, false, false, false, false,
|
||||
// P Q R S T U V W
|
||||
false, false, false, false, false, false, false, false,
|
||||
// X Y Z [ \ ] ^ _
|
||||
false, false, false, true , true , true , true , false,
|
||||
// ` a b c d e f g
|
||||
true , false, false, false, false, false, false, false,
|
||||
// h i j k l m n o
|
||||
false, false, false, false, false, false, false, false,
|
||||
// p q r s t u v w
|
||||
false, false, false, false, false, false, false, false,
|
||||
// x y z { | } ~ DEL
|
||||
false, false, false, true , true , true , false, true
|
||||
true, // space
|
||||
false, // !
|
||||
true, // "
|
||||
true, // #
|
||||
false, // $
|
||||
true, // %
|
||||
false, // &
|
||||
false, // '
|
||||
false, // (
|
||||
false, // )
|
||||
false, // *
|
||||
false, // +
|
||||
false, // ,
|
||||
false, // -
|
||||
false, // .
|
||||
true, // /
|
||||
false, // 0
|
||||
false, // 1
|
||||
false, // 2
|
||||
false, // 3
|
||||
false, // 4
|
||||
false, // 5
|
||||
false, // 6
|
||||
false, // 7
|
||||
false, // 8
|
||||
false, // 9
|
||||
true, // :
|
||||
false, // ;
|
||||
true, // <
|
||||
false, // =
|
||||
true, // >
|
||||
true, // ?
|
||||
false, // @
|
||||
false, // A
|
||||
false, // B
|
||||
false, // C
|
||||
false, // D
|
||||
false, // E
|
||||
false, // F
|
||||
false, // G
|
||||
false, // H
|
||||
false, // I
|
||||
false, // J
|
||||
false, // K
|
||||
false, // L
|
||||
false, // M
|
||||
false, // N
|
||||
false, // O
|
||||
false, // P
|
||||
false, // Q
|
||||
false, // R
|
||||
false, // S
|
||||
false, // T
|
||||
false, // U
|
||||
false, // V
|
||||
false, // W
|
||||
false, // X
|
||||
false, // Y
|
||||
false, // Z
|
||||
true, // [
|
||||
true, // \
|
||||
true, // ]
|
||||
true, // ^
|
||||
false, // _
|
||||
true, // `
|
||||
false, // a
|
||||
false, // b
|
||||
false, // c
|
||||
false, // d
|
||||
false, // e
|
||||
false, // f
|
||||
false, // g
|
||||
false, // h
|
||||
false, // i
|
||||
false, // j
|
||||
false, // k
|
||||
false, // l
|
||||
false, // m
|
||||
false, // n
|
||||
false, // o
|
||||
false, // p
|
||||
false, // q
|
||||
false, // r
|
||||
false, // s
|
||||
false, // t
|
||||
false, // u
|
||||
false, // v
|
||||
false, // w
|
||||
false, // x
|
||||
false, // y
|
||||
false, // z
|
||||
true, // {
|
||||
true, // |
|
||||
true, // }
|
||||
false, // ~
|
||||
true, // DEL
|
||||
];
|
||||
|
||||
_parsePackagesFile(SendPort sp,
|
||||
bool traceLoading,
|
||||
Uri packagesFile,
|
||||
List<int> data) {
|
||||
_parsePackagesFile(
|
||||
SendPort sp, bool traceLoading, Uri packagesFile, List<int> data) {
|
||||
// The first entry contains the location of the identified .packages file
|
||||
// instead of a mapping.
|
||||
var result = [packagesFile.toString(), null];
|
||||
|
@ -654,8 +667,9 @@ _parsePackagesFile(SendPort sp,
|
|||
// the characters.
|
||||
nonDot = nonDot || (char != _DOT);
|
||||
invalidPackageName = invalidPackageName ||
|
||||
(char < _SPACE) || (char > _DEL) ||
|
||||
_invalidPackageNameChars[char - _SPACE];
|
||||
(char < _SPACE) ||
|
||||
(char > _DEL) ||
|
||||
_invalidPackageNameChars[char - _SPACE];
|
||||
}
|
||||
}
|
||||
// Identify end of line.
|
||||
|
@ -669,7 +683,7 @@ _parsePackagesFile(SendPort sp,
|
|||
if (data[start] == _HASH) {
|
||||
if (traceLoading) {
|
||||
_log("Skipping comment in $packagesFile:\n"
|
||||
"${new String.fromCharCodes(data, start, end)}");
|
||||
"${new String.fromCharCodes(data, start, end)}");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
@ -679,10 +693,10 @@ _parsePackagesFile(SendPort sp,
|
|||
var line = new String.fromCharCodes(data, start, end);
|
||||
if (traceLoading) {
|
||||
_log("Line starts with ':' in $packagesFile:\n"
|
||||
"$line");
|
||||
"$line");
|
||||
}
|
||||
sp.send("Missing package name in $packagesFile:\n"
|
||||
"$line");
|
||||
"$line");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -691,10 +705,10 @@ _parsePackagesFile(SendPort sp,
|
|||
var line = new String.fromCharCodes(data, start, end);
|
||||
if (traceLoading) {
|
||||
_log("Line has no ':' in $packagesFile:\n"
|
||||
"$line");
|
||||
"$line");
|
||||
}
|
||||
sp.send("Missing ':' separator in $packagesFile:\n"
|
||||
"$line");
|
||||
"$line");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -707,7 +721,7 @@ _parsePackagesFile(SendPort sp,
|
|||
_log("Invalid package name $packageName in $packagesFile");
|
||||
}
|
||||
sp.send("Invalid package name '$packageName' in $packagesFile:\n"
|
||||
"$line");
|
||||
"$line");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -741,7 +755,7 @@ _loadPackagesFile(SendPort sp, bool traceLoading, Uri packagesFile) async {
|
|||
var data = await new File.fromUri(packagesFile).readAsBytes();
|
||||
if (traceLoading) {
|
||||
_log("Loaded packages file from $packagesFile:\n"
|
||||
"${new String.fromCharCodes(data)}");
|
||||
"${new String.fromCharCodes(data)}");
|
||||
}
|
||||
_parsePackagesFile(sp, traceLoading, packagesFile, data);
|
||||
} catch (e, s) {
|
||||
|
@ -812,9 +826,8 @@ _findPackagesFile(SendPort sp, bool traceLoading, Uri base) async {
|
|||
}
|
||||
}
|
||||
|
||||
Future<bool> _loadHttpPackagesFile(SendPort sp,
|
||||
bool traceLoading,
|
||||
Uri resource) async {
|
||||
Future<bool> _loadHttpPackagesFile(
|
||||
SendPort sp, bool traceLoading, Uri resource) async {
|
||||
try {
|
||||
if (_httpClient == null) {
|
||||
_httpClient = new HttpClient()..maxConnectionsPerHost = 6;
|
||||
|
@ -837,7 +850,7 @@ Future<bool> _loadHttpPackagesFile(SendPort sp,
|
|||
var data = builder.takeBytes();
|
||||
if (traceLoading) {
|
||||
_log("Loaded packages file from '$resource':\n"
|
||||
"${new String.fromCharCodes(data)}");
|
||||
"${new String.fromCharCodes(data)}");
|
||||
}
|
||||
_parsePackagesFile(sp, traceLoading, resource, data);
|
||||
} catch (e, s) {
|
||||
|
@ -849,7 +862,7 @@ Future<bool> _loadHttpPackagesFile(SendPort sp,
|
|||
return false;
|
||||
}
|
||||
|
||||
_loadPackagesData(sp, traceLoading, resource){
|
||||
_loadPackagesData(sp, traceLoading, resource) {
|
||||
try {
|
||||
var data = resource.data;
|
||||
var mime = data.mimeType;
|
||||
|
@ -857,8 +870,7 @@ _loadPackagesData(sp, traceLoading, resource){
|
|||
throw "MIME-type must be text/plain: $mime given.";
|
||||
}
|
||||
var charset = data.charset;
|
||||
if ((charset != "utf-8") &&
|
||||
(charset != "US-ASCII")) {
|
||||
if ((charset != "utf-8") && (charset != "US-ASCII")) {
|
||||
// The C++ portion of the embedder assumes UTF-8.
|
||||
throw "Only utf-8 or US-ASCII encodings are supported: $charset given.";
|
||||
}
|
||||
|
@ -872,10 +884,8 @@ _loadPackagesData(sp, traceLoading, resource){
|
|||
// report it's return value. This could be refactored so that it returns it's
|
||||
// value and the caller could wait on the future rather than a message on
|
||||
// SendPort.
|
||||
_handlePackagesRequest(SendPort sp,
|
||||
bool traceLoading,
|
||||
int tag,
|
||||
Uri resource) async {
|
||||
_handlePackagesRequest(
|
||||
SendPort sp, bool traceLoading, int tag, Uri resource) async {
|
||||
try {
|
||||
if (tag == -1) {
|
||||
if (resource.scheme == '' || resource.scheme == 'file') {
|
||||
|
@ -892,7 +902,7 @@ _handlePackagesRequest(SendPort sp,
|
|||
}
|
||||
} else {
|
||||
sp.send("Unsupported scheme used to locate .packages file: "
|
||||
"'$resource'.");
|
||||
"'$resource'.");
|
||||
}
|
||||
} else if (tag == -2) {
|
||||
if (traceLoading) {
|
||||
|
@ -914,7 +924,7 @@ _handlePackagesRequest(SendPort sp,
|
|||
_loadPackagesData(sp, traceLoading, resource);
|
||||
} else {
|
||||
sp.send("Unknown scheme (${resource.scheme}) for package file at "
|
||||
"'$resource'.");
|
||||
"'$resource'.");
|
||||
}
|
||||
} else {
|
||||
sp.send("Unknown packages request tag: $tag for '$resource'.");
|
||||
|
@ -942,21 +952,21 @@ void shutdownLoaders() {
|
|||
}
|
||||
|
||||
// See Dart_LibraryTag in dart_api.h
|
||||
const _Dart_kCanonicalizeUrl = 0; // Canonicalize the URL.
|
||||
const _Dart_kScriptTag = 1; // Load the root script.
|
||||
const _Dart_kSourceTag = 2; // Load a part source.
|
||||
const _Dart_kImportTag = 3; // Import a library.
|
||||
const _Dart_kCanonicalizeUrl = 0; // Canonicalize the URL.
|
||||
const _Dart_kScriptTag = 1; // Load the root script.
|
||||
const _Dart_kSourceTag = 2; // Load a part source.
|
||||
const _Dart_kImportTag = 3; // Import a library.
|
||||
|
||||
// Extra requests. Keep these in sync between loader.dart and builtin.dart.
|
||||
const _Dart_kInitLoader = 4; // Initialize the loader.
|
||||
const _Dart_kResourceLoad = 5; // Resource class support.
|
||||
const _Dart_kGetPackageRootUri = 6; // Uri of the packages/ directory.
|
||||
const _Dart_kGetPackageConfigUri = 7; // Uri of the .packages file.
|
||||
const _Dart_kResolvePackageUri = 8; // Resolve a package: uri.
|
||||
const _Dart_kInitLoader = 4; // Initialize the loader.
|
||||
const _Dart_kResourceLoad = 5; // Resource class support.
|
||||
const _Dart_kGetPackageRootUri = 6; // Uri of the packages/ directory.
|
||||
const _Dart_kGetPackageConfigUri = 7; // Uri of the .packages file.
|
||||
const _Dart_kResolvePackageUri = 8; // Resolve a package: uri.
|
||||
|
||||
// Extra requests. Keep these in sync between loader.dart and loader.cc.
|
||||
const _Dart_kImportExtension = 9; // Import a dart-ext: file.
|
||||
const _Dart_kResolveAsFilePath = 10; // Resolve uri to file path.
|
||||
const _Dart_kImportExtension = 9; // Import a dart-ext: file.
|
||||
const _Dart_kResolveAsFilePath = 10; // Resolve uri to file path.
|
||||
|
||||
// External entry point for loader requests.
|
||||
_processLoadRequest(request) {
|
||||
|
@ -983,74 +993,61 @@ _processLoadRequest(request) {
|
|||
|
||||
// Handle the request specified in the tag.
|
||||
switch (tag) {
|
||||
case _Dart_kScriptTag: {
|
||||
Uri uri = Uri.parse(request[4]);
|
||||
// Remember the root script.
|
||||
loaderState._rootScript = uri;
|
||||
_handleResourceRequest(loaderState,
|
||||
sp,
|
||||
traceLoading,
|
||||
tag,
|
||||
uri,
|
||||
uri,
|
||||
null);
|
||||
}
|
||||
break;
|
||||
case _Dart_kSourceTag:
|
||||
case _Dart_kImportTag: {
|
||||
// The url of the file being loaded.
|
||||
var uri = Uri.parse(request[4]);
|
||||
// The library that is importing/parting the file.
|
||||
String libraryUrl = request[5];
|
||||
_handleResourceRequest(loaderState,
|
||||
sp,
|
||||
traceLoading,
|
||||
tag,
|
||||
uri,
|
||||
uri,
|
||||
libraryUrl);
|
||||
}
|
||||
break;
|
||||
case _Dart_kInitLoader: {
|
||||
String packageRoot = request[4];
|
||||
String packagesFile = request[5];
|
||||
String workingDirectory = request[6];
|
||||
String rootScript = request[7];
|
||||
if (loaderState == null) {
|
||||
loaderState = new IsolateLoaderState(isolateId);
|
||||
isolateEmbedderData[isolateId] = loaderState;
|
||||
loaderState.init(packageRoot,
|
||||
packagesFile,
|
||||
workingDirectory,
|
||||
rootScript);
|
||||
case _Dart_kScriptTag:
|
||||
{
|
||||
Uri uri = Uri.parse(request[4]);
|
||||
// Remember the root script.
|
||||
loaderState._rootScript = uri;
|
||||
_handleResourceRequest(
|
||||
loaderState, sp, traceLoading, tag, uri, uri, null);
|
||||
}
|
||||
loaderState.sp = sp;
|
||||
assert(isolateEmbedderData[isolateId] == loaderState);
|
||||
}
|
||||
break;
|
||||
case _Dart_kResourceLoad: {
|
||||
Uri uri = Uri.parse(request[4]);
|
||||
_handleResourceRequest(loaderState,
|
||||
sp,
|
||||
traceLoading,
|
||||
tag,
|
||||
uri,
|
||||
uri,
|
||||
null);
|
||||
}
|
||||
break;
|
||||
break;
|
||||
case _Dart_kSourceTag:
|
||||
case _Dart_kImportTag:
|
||||
{
|
||||
// The url of the file being loaded.
|
||||
var uri = Uri.parse(request[4]);
|
||||
// The library that is importing/parting the file.
|
||||
String libraryUrl = request[5];
|
||||
_handleResourceRequest(
|
||||
loaderState, sp, traceLoading, tag, uri, uri, libraryUrl);
|
||||
}
|
||||
break;
|
||||
case _Dart_kInitLoader:
|
||||
{
|
||||
String packageRoot = request[4];
|
||||
String packagesFile = request[5];
|
||||
String workingDirectory = request[6];
|
||||
String rootScript = request[7];
|
||||
if (loaderState == null) {
|
||||
loaderState = new IsolateLoaderState(isolateId);
|
||||
isolateEmbedderData[isolateId] = loaderState;
|
||||
loaderState.init(
|
||||
packageRoot, packagesFile, workingDirectory, rootScript);
|
||||
}
|
||||
loaderState.sp = sp;
|
||||
assert(isolateEmbedderData[isolateId] == loaderState);
|
||||
}
|
||||
break;
|
||||
case _Dart_kResourceLoad:
|
||||
{
|
||||
Uri uri = Uri.parse(request[4]);
|
||||
_handleResourceRequest(
|
||||
loaderState, sp, traceLoading, tag, uri, uri, null);
|
||||
}
|
||||
break;
|
||||
case _Dart_kGetPackageRootUri:
|
||||
loaderState._triggerPackageResolution(() {
|
||||
// Respond with the package root (if any) after package resolution.
|
||||
sp.send(loaderState._packageRoot);
|
||||
});
|
||||
break;
|
||||
break;
|
||||
case _Dart_kGetPackageConfigUri:
|
||||
loaderState._triggerPackageResolution(() {
|
||||
// Respond with the packages config (if any) after package resolution.
|
||||
sp.send(loaderState._packageConfig);
|
||||
});
|
||||
break;
|
||||
break;
|
||||
case _Dart_kResolvePackageUri:
|
||||
Uri uri = Uri.parse(request[4]);
|
||||
loaderState._triggerPackageResolution(() {
|
||||
|
@ -1066,7 +1063,7 @@ _processLoadRequest(request) {
|
|||
}
|
||||
sp.send(resolvedUri);
|
||||
});
|
||||
break;
|
||||
break;
|
||||
case _Dart_kImportExtension:
|
||||
Uri uri = Uri.parse(request[4]);
|
||||
String libraryUri = request[5];
|
||||
|
@ -1082,15 +1079,14 @@ _processLoadRequest(request) {
|
|||
switch (pathUri.scheme) {
|
||||
case '':
|
||||
case 'file':
|
||||
_sendExtensionImportResponse(sp, uri, libraryUri,
|
||||
pathUri.toFilePath());
|
||||
break;
|
||||
_sendExtensionImportResponse(
|
||||
sp, uri, libraryUri, pathUri.toFilePath());
|
||||
break;
|
||||
case 'data':
|
||||
case 'http':
|
||||
case 'https':
|
||||
_sendExtensionImportResponse(sp, uri, libraryUri,
|
||||
pathUri.toString());
|
||||
break;
|
||||
_sendExtensionImportResponse(sp, uri, libraryUri, pathUri.toString());
|
||||
break;
|
||||
case 'package':
|
||||
// Start package resolution.
|
||||
loaderState._triggerPackageResolution(() {
|
||||
|
@ -1104,20 +1100,18 @@ _processLoadRequest(request) {
|
|||
}
|
||||
resolvedUri = null;
|
||||
}
|
||||
_sendExtensionImportResponse(sp,
|
||||
uri,
|
||||
libraryUri,
|
||||
resolvedUri.toString());
|
||||
_sendExtensionImportResponse(
|
||||
sp, uri, libraryUri, resolvedUri.toString());
|
||||
});
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
if (traceLoading) {
|
||||
_log('Unknown scheme (${pathUri.scheme}) in $pathUri.');
|
||||
}
|
||||
_sendExtensionImportResponse(sp, uri, libraryUri, null);
|
||||
break;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
break;
|
||||
case _Dart_kResolveAsFilePath:
|
||||
String uri = request[4];
|
||||
Uri resolvedUri = Uri.parse(_sanitizeWindowsPath(uri));
|
||||
|
@ -1136,7 +1130,7 @@ _processLoadRequest(request) {
|
|||
sp.send(msg);
|
||||
} else {
|
||||
throw "Cannot resolve scheme (${resolvedUri.scheme}) to file path"
|
||||
" for $resolvedUri";
|
||||
" for $resolvedUri";
|
||||
}
|
||||
} catch (e) {
|
||||
var msg = new List(5);
|
||||
|
@ -1147,7 +1141,7 @@ _processLoadRequest(request) {
|
|||
msg[4] = e.toString();
|
||||
sp.send(msg);
|
||||
}
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
_log('Unknown loader request tag=$tag from $isolateId');
|
||||
}
|
||||
|
|
|
@ -6,7 +6,8 @@ import "dart:_internal" show POWERS_OF_TEN;
|
|||
|
||||
// JSON conversion.
|
||||
|
||||
@patch _parseJson(String source, reviver(key, value)) {
|
||||
@patch
|
||||
_parseJson(String source, reviver(key, value)) {
|
||||
_BuildJsonListener listener;
|
||||
if (reviver == null) {
|
||||
listener = new _BuildJsonListener();
|
||||
|
@ -21,10 +22,10 @@ import "dart:_internal" show POWERS_OF_TEN;
|
|||
return listener.result;
|
||||
}
|
||||
|
||||
@patch class Utf8Decoder {
|
||||
@patch
|
||||
class Utf8Decoder {
|
||||
@patch
|
||||
Converter<List<int>, T> fuse<T>(
|
||||
Converter<String, T> next) {
|
||||
Converter<List<int>, T> fuse<T>(Converter<String, T> next) {
|
||||
if (next is JsonDecoder) {
|
||||
return new _JsonUtf8Decoder(next._reviver, this._allowMalformed)
|
||||
as dynamic/*=Converter<List<int>, T>*/;
|
||||
|
@ -37,7 +38,7 @@ import "dart:_internal" show POWERS_OF_TEN;
|
|||
@patch
|
||||
static String _convertIntercepted(
|
||||
bool allowMalformed, List<int> codeUnits, int start, int end) {
|
||||
return null; // This call was not intercepted.
|
||||
return null; // This call was not intercepted.
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -123,10 +124,21 @@ class _BuildJsonListener extends _JsonListener {
|
|||
if (currentContainer is Map) key = stack.removeLast();
|
||||
}
|
||||
|
||||
void handleString(String value) { this.value = value; }
|
||||
void handleNumber(num value) { this.value = value; }
|
||||
void handleBool(bool value) { this.value = value; }
|
||||
void handleNull() { this.value = null; }
|
||||
void handleString(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
void handleNumber(num value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
void handleBool(bool value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
void handleNull() {
|
||||
this.value = null;
|
||||
}
|
||||
|
||||
void beginObject() {
|
||||
pushContainer();
|
||||
|
@ -218,7 +230,7 @@ class _NumberBuffer {
|
|||
static int _initialCapacity(int minCapacity) {
|
||||
minCapacity += kDefaultOverhead;
|
||||
if (minCapacity < minCapacity) return minCapacity;
|
||||
minCapacity = (minCapacity + 3) & ~3; // Round to multiple of four.
|
||||
minCapacity = (minCapacity + 3) & ~3; // Round to multiple of four.
|
||||
return minCapacity;
|
||||
}
|
||||
|
||||
|
@ -277,109 +289,109 @@ abstract class _ChunkedJsonParser {
|
|||
// gets to the next state (not empty, doesn't allow a value).
|
||||
|
||||
// State building-block constants.
|
||||
static const int TOP_LEVEL = 0;
|
||||
static const int INSIDE_ARRAY = 1;
|
||||
static const int INSIDE_OBJECT = 2;
|
||||
static const int AFTER_COLON = 3; // Always inside object.
|
||||
static const int TOP_LEVEL = 0;
|
||||
static const int INSIDE_ARRAY = 1;
|
||||
static const int INSIDE_OBJECT = 2;
|
||||
static const int AFTER_COLON = 3; // Always inside object.
|
||||
|
||||
static const int ALLOW_STRING_MASK = 8; // Allowed if zero.
|
||||
static const int ALLOW_VALUE_MASK = 4; // Allowed if zero.
|
||||
static const int ALLOW_VALUE = 0;
|
||||
static const int STRING_ONLY = 4;
|
||||
static const int NO_VALUES = 12;
|
||||
static const int ALLOW_STRING_MASK = 8; // Allowed if zero.
|
||||
static const int ALLOW_VALUE_MASK = 4; // Allowed if zero.
|
||||
static const int ALLOW_VALUE = 0;
|
||||
static const int STRING_ONLY = 4;
|
||||
static const int NO_VALUES = 12;
|
||||
|
||||
// Objects and arrays are "empty" until their first property/element.
|
||||
// At this position, they may either have an entry or a close-bracket.
|
||||
static const int EMPTY = 0;
|
||||
static const int NON_EMPTY = 16;
|
||||
static const int EMPTY_MASK = 16; // Empty if zero.
|
||||
static const int EMPTY = 0;
|
||||
static const int NON_EMPTY = 16;
|
||||
static const int EMPTY_MASK = 16; // Empty if zero.
|
||||
|
||||
// Actual states : Context | Is empty? | Next?
|
||||
static const int STATE_INITIAL = TOP_LEVEL | EMPTY | ALLOW_VALUE;
|
||||
static const int STATE_END = TOP_LEVEL | NON_EMPTY | NO_VALUES;
|
||||
// Actual states : Context | Is empty? | Next?
|
||||
static const int STATE_INITIAL = TOP_LEVEL | EMPTY | ALLOW_VALUE;
|
||||
static const int STATE_END = TOP_LEVEL | NON_EMPTY | NO_VALUES;
|
||||
|
||||
static const int STATE_ARRAY_EMPTY = INSIDE_ARRAY | EMPTY | ALLOW_VALUE;
|
||||
static const int STATE_ARRAY_VALUE = INSIDE_ARRAY | NON_EMPTY | NO_VALUES;
|
||||
static const int STATE_ARRAY_COMMA = INSIDE_ARRAY | NON_EMPTY | ALLOW_VALUE;
|
||||
static const int STATE_ARRAY_EMPTY = INSIDE_ARRAY | EMPTY | ALLOW_VALUE;
|
||||
static const int STATE_ARRAY_VALUE = INSIDE_ARRAY | NON_EMPTY | NO_VALUES;
|
||||
static const int STATE_ARRAY_COMMA = INSIDE_ARRAY | NON_EMPTY | ALLOW_VALUE;
|
||||
|
||||
static const int STATE_OBJECT_EMPTY = INSIDE_OBJECT | EMPTY | STRING_ONLY;
|
||||
static const int STATE_OBJECT_KEY = INSIDE_OBJECT | NON_EMPTY | NO_VALUES;
|
||||
static const int STATE_OBJECT_COLON = AFTER_COLON | NON_EMPTY | ALLOW_VALUE;
|
||||
static const int STATE_OBJECT_VALUE = AFTER_COLON | NON_EMPTY | NO_VALUES;
|
||||
static const int STATE_OBJECT_EMPTY = INSIDE_OBJECT | EMPTY | STRING_ONLY;
|
||||
static const int STATE_OBJECT_KEY = INSIDE_OBJECT | NON_EMPTY | NO_VALUES;
|
||||
static const int STATE_OBJECT_COLON = AFTER_COLON | NON_EMPTY | ALLOW_VALUE;
|
||||
static const int STATE_OBJECT_VALUE = AFTER_COLON | NON_EMPTY | NO_VALUES;
|
||||
static const int STATE_OBJECT_COMMA = INSIDE_OBJECT | NON_EMPTY | STRING_ONLY;
|
||||
|
||||
// Bits set in state after successfully reading a value.
|
||||
// This transitions the state to expect the next punctuation.
|
||||
static const int VALUE_READ_BITS = NON_EMPTY | NO_VALUES;
|
||||
static const int VALUE_READ_BITS = NON_EMPTY | NO_VALUES;
|
||||
|
||||
// Character code constants.
|
||||
static const int BACKSPACE = 0x08;
|
||||
static const int TAB = 0x09;
|
||||
static const int NEWLINE = 0x0a;
|
||||
static const int BACKSPACE = 0x08;
|
||||
static const int TAB = 0x09;
|
||||
static const int NEWLINE = 0x0a;
|
||||
static const int CARRIAGE_RETURN = 0x0d;
|
||||
static const int FORM_FEED = 0x0c;
|
||||
static const int SPACE = 0x20;
|
||||
static const int QUOTE = 0x22;
|
||||
static const int PLUS = 0x2b;
|
||||
static const int COMMA = 0x2c;
|
||||
static const int MINUS = 0x2d;
|
||||
static const int DECIMALPOINT = 0x2e;
|
||||
static const int SLASH = 0x2f;
|
||||
static const int CHAR_0 = 0x30;
|
||||
static const int CHAR_9 = 0x39;
|
||||
static const int COLON = 0x3a;
|
||||
static const int CHAR_E = 0x45;
|
||||
static const int LBRACKET = 0x5b;
|
||||
static const int BACKSLASH = 0x5c;
|
||||
static const int RBRACKET = 0x5d;
|
||||
static const int CHAR_a = 0x61;
|
||||
static const int CHAR_b = 0x62;
|
||||
static const int CHAR_e = 0x65;
|
||||
static const int CHAR_f = 0x66;
|
||||
static const int CHAR_l = 0x6c;
|
||||
static const int CHAR_n = 0x6e;
|
||||
static const int CHAR_r = 0x72;
|
||||
static const int CHAR_s = 0x73;
|
||||
static const int CHAR_t = 0x74;
|
||||
static const int CHAR_u = 0x75;
|
||||
static const int LBRACE = 0x7b;
|
||||
static const int RBRACE = 0x7d;
|
||||
static const int FORM_FEED = 0x0c;
|
||||
static const int SPACE = 0x20;
|
||||
static const int QUOTE = 0x22;
|
||||
static const int PLUS = 0x2b;
|
||||
static const int COMMA = 0x2c;
|
||||
static const int MINUS = 0x2d;
|
||||
static const int DECIMALPOINT = 0x2e;
|
||||
static const int SLASH = 0x2f;
|
||||
static const int CHAR_0 = 0x30;
|
||||
static const int CHAR_9 = 0x39;
|
||||
static const int COLON = 0x3a;
|
||||
static const int CHAR_E = 0x45;
|
||||
static const int LBRACKET = 0x5b;
|
||||
static const int BACKSLASH = 0x5c;
|
||||
static const int RBRACKET = 0x5d;
|
||||
static const int CHAR_a = 0x61;
|
||||
static const int CHAR_b = 0x62;
|
||||
static const int CHAR_e = 0x65;
|
||||
static const int CHAR_f = 0x66;
|
||||
static const int CHAR_l = 0x6c;
|
||||
static const int CHAR_n = 0x6e;
|
||||
static const int CHAR_r = 0x72;
|
||||
static const int CHAR_s = 0x73;
|
||||
static const int CHAR_t = 0x74;
|
||||
static const int CHAR_u = 0x75;
|
||||
static const int LBRACE = 0x7b;
|
||||
static const int RBRACE = 0x7d;
|
||||
|
||||
// State of partial value at chunk split.
|
||||
static const int NO_PARTIAL = 0;
|
||||
static const int PARTIAL_STRING = 1;
|
||||
static const int PARTIAL_NUMERAL = 2;
|
||||
static const int PARTIAL_KEYWORD = 3;
|
||||
static const int MASK_PARTIAL = 3;
|
||||
static const int NO_PARTIAL = 0;
|
||||
static const int PARTIAL_STRING = 1;
|
||||
static const int PARTIAL_NUMERAL = 2;
|
||||
static const int PARTIAL_KEYWORD = 3;
|
||||
static const int MASK_PARTIAL = 3;
|
||||
|
||||
// Partial states for numerals. Values can be |'ed with PARTIAL_NUMERAL.
|
||||
static const int NUM_SIGN = 0; // After initial '-'.
|
||||
static const int NUM_ZERO = 4; // After '0' as first digit.
|
||||
static const int NUM_DIGIT = 8; // After digit, no '.' or 'e' seen.
|
||||
static const int NUM_DOT = 12; // After '.'.
|
||||
static const int NUM_DOT_DIGIT = 16; // After a decimal digit (after '.').
|
||||
static const int NUM_E = 20; // After 'e' or 'E'.
|
||||
static const int NUM_E_SIGN = 24; // After '-' or '+' after 'e' or 'E'.
|
||||
static const int NUM_E_DIGIT = 28; // After exponent digit.
|
||||
static const int NUM_SUCCESS = 32; // Never stored as partial state.
|
||||
static const int NUM_SIGN = 0; // After initial '-'.
|
||||
static const int NUM_ZERO = 4; // After '0' as first digit.
|
||||
static const int NUM_DIGIT = 8; // After digit, no '.' or 'e' seen.
|
||||
static const int NUM_DOT = 12; // After '.'.
|
||||
static const int NUM_DOT_DIGIT = 16; // After a decimal digit (after '.').
|
||||
static const int NUM_E = 20; // After 'e' or 'E'.
|
||||
static const int NUM_E_SIGN = 24; // After '-' or '+' after 'e' or 'E'.
|
||||
static const int NUM_E_DIGIT = 28; // After exponent digit.
|
||||
static const int NUM_SUCCESS = 32; // Never stored as partial state.
|
||||
|
||||
// Partial states for strings.
|
||||
static const int STR_PLAIN = 0; // Inside string, but not escape.
|
||||
static const int STR_ESCAPE = 4; // After '\'.
|
||||
static const int STR_U = 16; // After '\u' and 0-3 hex digits.
|
||||
static const int STR_U_COUNT_SHIFT = 2; // Hex digit count in bits 2-3.
|
||||
static const int STR_U_VALUE_SHIFT = 5; // Hex digit value in bits 5+.
|
||||
static const int STR_PLAIN = 0; // Inside string, but not escape.
|
||||
static const int STR_ESCAPE = 4; // After '\'.
|
||||
static const int STR_U = 16; // After '\u' and 0-3 hex digits.
|
||||
static const int STR_U_COUNT_SHIFT = 2; // Hex digit count in bits 2-3.
|
||||
static const int STR_U_VALUE_SHIFT = 5; // Hex digit value in bits 5+.
|
||||
|
||||
// Partial states for keywords.
|
||||
static const int KWD_TYPE_MASK = 12;
|
||||
static const int KWD_TYPE_SHIFT = 2;
|
||||
static const int KWD_NULL = 0; // Prefix of "null" seen.
|
||||
static const int KWD_TRUE = 4; // Prefix of "true" seen.
|
||||
static const int KWD_FALSE = 8; // Prefix of "false" seen.
|
||||
static const int KWD_COUNT_SHIFT = 4; // Prefix length in bits 4+.
|
||||
static const int KWD_TYPE_MASK = 12;
|
||||
static const int KWD_TYPE_SHIFT = 2;
|
||||
static const int KWD_NULL = 0; // Prefix of "null" seen.
|
||||
static const int KWD_TRUE = 4; // Prefix of "true" seen.
|
||||
static const int KWD_FALSE = 8; // Prefix of "false" seen.
|
||||
static const int KWD_COUNT_SHIFT = 4; // Prefix length in bits 4+.
|
||||
|
||||
// Mask used to mask off two lower bits.
|
||||
static const int TWO_BIT_MASK = 3;
|
||||
static const int TWO_BIT_MASK = 3;
|
||||
|
||||
final _JsonListener listener;
|
||||
|
||||
|
@ -446,7 +458,7 @@ abstract class _ChunkedJsonParser {
|
|||
* Restore a state pushed with [saveState].
|
||||
*/
|
||||
int restoreState() {
|
||||
return states.removeLast(); // Throws if empty.
|
||||
return states.removeLast(); // Throws if empty.
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -477,7 +489,7 @@ abstract class _ChunkedJsonParser {
|
|||
fail(chunkEnd, "Unterminated string");
|
||||
} else {
|
||||
assert(partialType == PARTIAL_KEYWORD);
|
||||
fail(chunkEnd); // Incomplete literal.
|
||||
fail(chunkEnd); // Incomplete literal.
|
||||
}
|
||||
}
|
||||
if (state != STATE_END) {
|
||||
|
@ -577,7 +589,7 @@ abstract class _ChunkedJsonParser {
|
|||
* The format is expected to be correct.
|
||||
*/
|
||||
int parseInt(int start, int end) {
|
||||
const int asciiBits = 0x7f; // Integer literals are ASCII only.
|
||||
const int asciiBits = 0x7f; // Integer literals are ASCII only.
|
||||
return int.parse(getString(start, end, asciiBits));
|
||||
}
|
||||
|
||||
|
@ -589,7 +601,7 @@ abstract class _ChunkedJsonParser {
|
|||
* built exactly during parsing.
|
||||
*/
|
||||
double parseDouble(int start, int end) {
|
||||
const int asciiBits = 0x7f; // Double literals are ASCII only.
|
||||
const int asciiBits = 0x7f; // Double literals are ASCII only.
|
||||
return double.parse(getString(start, end, asciiBits));
|
||||
}
|
||||
|
||||
|
@ -645,7 +657,8 @@ abstract class _ChunkedJsonParser {
|
|||
_NumberBuffer buffer = this.buffer;
|
||||
this.buffer = null;
|
||||
int end = chunkEnd;
|
||||
toBailout: {
|
||||
toBailout:
|
||||
{
|
||||
if (position == end) break toBailout;
|
||||
int char = getChar(position);
|
||||
int digit = char ^ CHAR_0;
|
||||
|
@ -993,7 +1006,7 @@ abstract class _ChunkedJsonParser {
|
|||
int bits = 0;
|
||||
while (position < end) {
|
||||
int char = getChar(position++);
|
||||
bits |= char; // Includes final '"', but that never matters.
|
||||
bits |= char; // Includes final '"', but that never matters.
|
||||
// BACKSLASH is larger than QUOTE and SPACE.
|
||||
if (char > BACKSLASH) {
|
||||
continue;
|
||||
|
@ -1039,9 +1052,10 @@ abstract class _ChunkedJsonParser {
|
|||
* Returns [chunkEnd] so it can be used as part of a return statement.
|
||||
*/
|
||||
int chunkStringEscapeU(int count, int value) {
|
||||
partialState = PARTIAL_STRING | STR_U |
|
||||
(count << STR_U_COUNT_SHIFT) |
|
||||
(value << STR_U_VALUE_SHIFT);
|
||||
partialState = PARTIAL_STRING |
|
||||
STR_U |
|
||||
(count << STR_U_COUNT_SHIFT) |
|
||||
(value << STR_U_VALUE_SHIFT);
|
||||
return chunkEnd;
|
||||
}
|
||||
|
||||
|
@ -1068,7 +1082,7 @@ abstract class _ChunkedJsonParser {
|
|||
int char = getChar(position++);
|
||||
if (char > BACKSLASH) continue;
|
||||
if (char < SPACE) {
|
||||
return fail(position - 1); // Control character in string.
|
||||
return fail(position - 1); // Control character in string.
|
||||
}
|
||||
if (char == QUOTE) {
|
||||
int quotePosition = position - 1;
|
||||
|
@ -1090,7 +1104,7 @@ abstract class _ChunkedJsonParser {
|
|||
if (position == end) return position;
|
||||
start = position;
|
||||
}
|
||||
return -1; // UNREACHABLE.
|
||||
return -1; // UNREACHABLE.
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1106,11 +1120,21 @@ abstract class _ChunkedJsonParser {
|
|||
int char = getChar(position++);
|
||||
int length = chunkEnd;
|
||||
switch (char) {
|
||||
case CHAR_b: char = BACKSPACE; break;
|
||||
case CHAR_f: char = FORM_FEED; break;
|
||||
case CHAR_n: char = NEWLINE; break;
|
||||
case CHAR_r: char = CARRIAGE_RETURN; break;
|
||||
case CHAR_t: char = TAB; break;
|
||||
case CHAR_b:
|
||||
char = BACKSPACE;
|
||||
break;
|
||||
case CHAR_f:
|
||||
char = FORM_FEED;
|
||||
break;
|
||||
case CHAR_n:
|
||||
char = NEWLINE;
|
||||
break;
|
||||
case CHAR_r:
|
||||
char = CARRIAGE_RETURN;
|
||||
break;
|
||||
case CHAR_t:
|
||||
char = TAB;
|
||||
break;
|
||||
case SLASH:
|
||||
case BACKSLASH:
|
||||
case QUOTE:
|
||||
|
@ -1270,7 +1294,7 @@ abstract class _ChunkedJsonParser {
|
|||
int expSign = 1;
|
||||
int exponent = 0;
|
||||
if (char == PLUS || char == MINUS) {
|
||||
expSign = 0x2C - char; // -1 for MINUS, +1 for PLUS
|
||||
expSign = 0x2C - char; // -1 for MINUS, +1 for PLUS
|
||||
position++;
|
||||
if (position == length) return beginChunkNumber(NUM_E_SIGN, start);
|
||||
char = getChar(position);
|
||||
|
@ -1376,8 +1400,10 @@ class _JsonStringParser extends _ChunkedJsonParser {
|
|||
}
|
||||
}
|
||||
|
||||
@patch class JsonDecoder {
|
||||
@patch StringConversionSink startChunkedConversion(Sink<Object> sink) {
|
||||
@patch
|
||||
class JsonDecoder {
|
||||
@patch
|
||||
StringConversionSink startChunkedConversion(Sink<Object> sink) {
|
||||
return new _JsonStringDecoderSink(this._reviver, sink);
|
||||
}
|
||||
}
|
||||
|
@ -1394,7 +1420,8 @@ class _JsonStringDecoderSink extends StringConversionSinkBase {
|
|||
final Sink<Object> _sink;
|
||||
|
||||
_JsonStringDecoderSink(reviver, this._sink)
|
||||
: _reviver = reviver, _parser = _createParser(reviver);
|
||||
: _reviver = reviver,
|
||||
_parser = _createParser(reviver);
|
||||
|
||||
static _ChunkedJsonParser _createParser(reviver) {
|
||||
_BuildJsonListener listener;
|
||||
|
@ -1491,8 +1518,8 @@ class _Utf8StringBuffer {
|
|||
* [missing] values are always the same, but they may differ if continuing
|
||||
* after a partial sequence.
|
||||
*/
|
||||
int addContinuation(List<int> utf8, int position, int end,
|
||||
int size, int missing, int value) {
|
||||
int addContinuation(
|
||||
List<int> utf8, int position, int end, int size, int missing, int value) {
|
||||
int codeEnd = position + missing;
|
||||
do {
|
||||
if (position == end) {
|
||||
|
@ -1507,8 +1534,11 @@ class _Utf8StringBuffer {
|
|||
addCharCode(0xFFFD);
|
||||
return position;
|
||||
}
|
||||
throw new FormatException("Expected UTF-8 continuation byte, "
|
||||
"found $char", utf8, position);
|
||||
throw new FormatException(
|
||||
"Expected UTF-8 continuation byte, "
|
||||
"found $char",
|
||||
utf8,
|
||||
position);
|
||||
}
|
||||
value = 64 * value + (char & MASK_CONTINUE_VALUE);
|
||||
position++;
|
||||
|
@ -1520,7 +1550,9 @@ class _Utf8StringBuffer {
|
|||
} else {
|
||||
throw new FormatException(
|
||||
"Invalid encoding: U+${value.toRadixString(16).padLeft(4, '0')}"
|
||||
" encoded in ${size + 1} bytes.", utf8, position - 1);
|
||||
" encoded in ${size + 1} bytes.",
|
||||
utf8,
|
||||
position - 1);
|
||||
}
|
||||
}
|
||||
addCharCode(value);
|
||||
|
@ -1539,7 +1571,7 @@ class _Utf8StringBuffer {
|
|||
}
|
||||
}
|
||||
if (isLatin1 && char > 0xff) {
|
||||
_to16Bit(); // Also grows a little if close to full.
|
||||
_to16Bit(); // Also grows a little if close to full.
|
||||
}
|
||||
int length = this.length;
|
||||
if (char <= MAX_THREE_BYTE) {
|
||||
|
@ -1592,8 +1624,8 @@ class _Utf8StringBuffer {
|
|||
int missing = (partialState >> SHIFT_MISSING) & MASK_TWO_BIT;
|
||||
int value = partialState >> SHIFT_VALUE;
|
||||
partialState = NO_PARTIAL;
|
||||
position = addContinuation(utf8, position, end,
|
||||
continueByteCount, missing, value);
|
||||
position = addContinuation(
|
||||
utf8, position, end, continueByteCount, missing, value);
|
||||
if (position == end) return;
|
||||
}
|
||||
// Keep index and capacity in local variables while looping over
|
||||
|
@ -1618,28 +1650,31 @@ class _Utf8StringBuffer {
|
|||
addCharCode(0xFFFD);
|
||||
position++;
|
||||
} else {
|
||||
throw new FormatException("Unexepected UTF-8 continuation byte",
|
||||
utf8, position);
|
||||
throw new FormatException(
|
||||
"Unexepected UTF-8 continuation byte", utf8, position);
|
||||
}
|
||||
} else if (char < 0xE0) { // C0-DF
|
||||
} else if (char < 0xE0) {
|
||||
// C0-DF
|
||||
// Two-byte.
|
||||
position = addContinuation(utf8, position + 1, end, 1, 1,
|
||||
char & MASK_TWO_BYTE);
|
||||
} else if (char < 0xF0) { // E0-EF
|
||||
position = addContinuation(
|
||||
utf8, position + 1, end, 1, 1, char & MASK_TWO_BYTE);
|
||||
} else if (char < 0xF0) {
|
||||
// E0-EF
|
||||
// Three-byte.
|
||||
position = addContinuation(utf8, position + 1, end, 2, 2,
|
||||
char & MASK_THREE_BYTE);
|
||||
} else if (char < 0xF8) { // F0-F7
|
||||
position = addContinuation(
|
||||
utf8, position + 1, end, 2, 2, char & MASK_THREE_BYTE);
|
||||
} else if (char < 0xF8) {
|
||||
// F0-F7
|
||||
// Four-byte.
|
||||
position = addContinuation(utf8, position + 1, end, 3, 3,
|
||||
char & MASK_FOUR_BYTE);
|
||||
position = addContinuation(
|
||||
utf8, position + 1, end, 3, 3, char & MASK_FOUR_BYTE);
|
||||
} else {
|
||||
if (allowMalformed) {
|
||||
addCharCode(0xFFFD);
|
||||
position++;
|
||||
} else {
|
||||
throw new FormatException("Invalid UTF-8 byte: $char",
|
||||
utf8, position);
|
||||
throw new FormatException(
|
||||
"Invalid UTF-8 byte: $char", utf8, position);
|
||||
}
|
||||
}
|
||||
index = length;
|
||||
|
@ -1665,8 +1700,8 @@ class _Utf8StringBuffer {
|
|||
value >>= 6;
|
||||
}
|
||||
source[0] = value | (0x3c0 >> (continueByteCount - 1));
|
||||
throw new FormatException("Incomplete UTF-8 sequence",
|
||||
source, source.length);
|
||||
throw new FormatException(
|
||||
"Incomplete UTF-8 sequence", source, source.length);
|
||||
}
|
||||
}
|
||||
return new String.fromCharCodes(buffer, 0, length);
|
||||
|
@ -1728,8 +1763,7 @@ class _JsonUtf8Parser extends _ChunkedJsonParser {
|
|||
}
|
||||
}
|
||||
|
||||
double _parseDouble(String source, int start, int end)
|
||||
native "Double_parse";
|
||||
double _parseDouble(String source, int start, int end) native "Double_parse";
|
||||
|
||||
/**
|
||||
* Implements the chunked conversion from a UTF-8 encoding of JSON
|
||||
|
|
|
@ -11,16 +11,19 @@ abstract class _IntegerImplementation {
|
|||
if (result != null) return result;
|
||||
return other._toBigint()._addFromInteger(this);
|
||||
}
|
||||
|
||||
num operator -(num other) {
|
||||
var result = other._subFromInteger(this);
|
||||
if (result != null) return result;
|
||||
return other._toBigint()._subFromInteger(this);
|
||||
}
|
||||
|
||||
num operator *(num other) {
|
||||
var result = other._mulFromInteger(this);
|
||||
if (result != null) return result;
|
||||
return other._toBigint()._mulFromInteger(this);
|
||||
}
|
||||
|
||||
num operator ~/(num other) {
|
||||
if ((other is int) && (other == 0)) {
|
||||
throw const IntegerDivisionByZeroException();
|
||||
|
@ -29,9 +32,11 @@ abstract class _IntegerImplementation {
|
|||
if (result != null) return result;
|
||||
return other._toBigint()._truncDivFromInteger(this);
|
||||
}
|
||||
|
||||
num operator /(num other) {
|
||||
return this.toDouble() / other.toDouble();
|
||||
}
|
||||
|
||||
num operator %(num other) {
|
||||
if ((other is int) && (other == 0)) {
|
||||
throw const IntegerDivisionByZeroException();
|
||||
|
@ -40,27 +45,33 @@ abstract class _IntegerImplementation {
|
|||
if (result != null) return result;
|
||||
return other._toBigint()._moduloFromInteger(this);
|
||||
}
|
||||
|
||||
int operator -() {
|
||||
return 0 - this;
|
||||
}
|
||||
|
||||
int operator &(int other) {
|
||||
var result = other._bitAndFromInteger(this);
|
||||
if (result != null) return result;
|
||||
return other._toBigint()._bitAndFromInteger(this);
|
||||
}
|
||||
|
||||
int operator |(int other) {
|
||||
var result = other._bitOrFromInteger(this);
|
||||
if (result != null) return result;
|
||||
return other._toBigint()._bitOrFromInteger(this);
|
||||
}
|
||||
|
||||
int operator ^(int other) {
|
||||
var result = other._bitXorFromInteger(this);
|
||||
if (result != null) return result;
|
||||
return other._toBigint()._bitXorFromInteger(this);
|
||||
}
|
||||
|
||||
num remainder(num other) {
|
||||
return other._remainderFromInteger(this);
|
||||
}
|
||||
|
||||
int _bitAndFromSmi(int other) native "Integer_bitAndFromInteger";
|
||||
int _bitAndFromInteger(int other) native "Integer_bitAndFromInteger";
|
||||
int _bitOrFromInteger(int other) native "Integer_bitOrFromInteger";
|
||||
|
@ -73,28 +84,35 @@ abstract class _IntegerImplementation {
|
|||
int _remainderFromInteger(int other) {
|
||||
return other - (other ~/ this) * this;
|
||||
}
|
||||
|
||||
int operator >>(int other) {
|
||||
var result = other._shrFromInt(this);
|
||||
if (result != null) return result;
|
||||
return other._toBigint()._shrFromInt(this);
|
||||
}
|
||||
|
||||
int operator <<(int other) {
|
||||
var result = other._shlFromInt(this);
|
||||
if (result != null) return result;
|
||||
return other._toBigint()._shlFromInt(this);
|
||||
}
|
||||
|
||||
bool operator <(num other) {
|
||||
return other > this;
|
||||
}
|
||||
|
||||
bool operator >(num other) {
|
||||
return other._greaterThanFromInteger(this);
|
||||
}
|
||||
|
||||
bool operator >=(num other) {
|
||||
return (this == other) || (this > other);
|
||||
return (this == other) || (this > other);
|
||||
}
|
||||
|
||||
bool operator <=(num other) {
|
||||
return (this == other) || (this < other);
|
||||
}
|
||||
|
||||
bool _greaterThanFromInteger(int other)
|
||||
native "Integer_greaterThanFromInteger";
|
||||
bool operator ==(other) {
|
||||
|
@ -103,13 +121,16 @@ abstract class _IntegerImplementation {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool _equalToInteger(int other) native "Integer_equalToInteger";
|
||||
int abs() {
|
||||
return this < 0 ? -this : this;
|
||||
}
|
||||
|
||||
int get sign {
|
||||
return (this > 0) ? 1 : (this < 0) ? -1 : 0;
|
||||
}
|
||||
|
||||
bool get isEven => ((this & 1) == 0);
|
||||
bool get isOdd => !isEven;
|
||||
bool get isNaN => false;
|
||||
|
@ -134,7 +155,7 @@ abstract class _IntegerImplementation {
|
|||
int compareTo(num other) {
|
||||
const int EQUAL = 0, LESS = -1, GREATER = 1;
|
||||
if (other is double) {
|
||||
const int MAX_EXACT_INT_TO_DOUBLE = 9007199254740992; // 2^53.
|
||||
const int MAX_EXACT_INT_TO_DOUBLE = 9007199254740992; // 2^53.
|
||||
const int MIN_EXACT_INT_TO_DOUBLE = -MAX_EXACT_INT_TO_DOUBLE;
|
||||
double d = other;
|
||||
if (d.isInfinite) {
|
||||
|
@ -161,15 +182,37 @@ abstract class _IntegerImplementation {
|
|||
}
|
||||
}
|
||||
|
||||
int round() { return this; }
|
||||
int floor() { return this; }
|
||||
int ceil() { return this; }
|
||||
int truncate() { return this; }
|
||||
int round() {
|
||||
return this;
|
||||
}
|
||||
|
||||
double roundToDouble() { return this.toDouble(); }
|
||||
double floorToDouble() { return this.toDouble(); }
|
||||
double ceilToDouble() { return this.toDouble(); }
|
||||
double truncateToDouble() { return this.toDouble(); }
|
||||
int floor() {
|
||||
return this;
|
||||
}
|
||||
|
||||
int ceil() {
|
||||
return this;
|
||||
}
|
||||
|
||||
int truncate() {
|
||||
return this;
|
||||
}
|
||||
|
||||
double roundToDouble() {
|
||||
return this.toDouble();
|
||||
}
|
||||
|
||||
double floorToDouble() {
|
||||
return this.toDouble();
|
||||
}
|
||||
|
||||
double ceilToDouble() {
|
||||
return this.toDouble();
|
||||
}
|
||||
|
||||
double truncateToDouble() {
|
||||
return this.toDouble();
|
||||
}
|
||||
|
||||
num clamp(num lowerLimit, num upperLimit) {
|
||||
if (lowerLimit is! num) {
|
||||
|
@ -196,17 +239,30 @@ abstract class _IntegerImplementation {
|
|||
return this;
|
||||
}
|
||||
|
||||
int toInt() { return this; }
|
||||
double toDouble() { return new _Double.fromInteger(this); }
|
||||
_Bigint _toBigint() { return new _Bigint._fromInt(this); }
|
||||
num _toBigintOrDouble() { return _toBigint(); }
|
||||
int toInt() {
|
||||
return this;
|
||||
}
|
||||
|
||||
double toDouble() {
|
||||
return new _Double.fromInteger(this);
|
||||
}
|
||||
|
||||
_Bigint _toBigint() {
|
||||
return new _Bigint._fromInt(this);
|
||||
}
|
||||
|
||||
num _toBigintOrDouble() {
|
||||
return _toBigint();
|
||||
}
|
||||
|
||||
String toStringAsFixed(int fractionDigits) {
|
||||
return this.toDouble().toStringAsFixed(fractionDigits);
|
||||
}
|
||||
|
||||
String toStringAsExponential([int fractionDigits]) {
|
||||
return this.toDouble().toStringAsExponential(fractionDigits);
|
||||
}
|
||||
|
||||
String toStringAsPrecision(int precision) {
|
||||
return this.toDouble().toStringAsPrecision(precision);
|
||||
}
|
||||
|
@ -229,7 +285,7 @@ abstract class _IntegerImplementation {
|
|||
value ~/= radix;
|
||||
temp.add(_digits.codeUnitAt(digit));
|
||||
} while (value > 0);
|
||||
if (isNegative) temp.add(0x2d); // '-'.
|
||||
if (isNegative) temp.add(0x2d); // '-'.
|
||||
|
||||
_OneByteString string = _OneByteString._allocate(temp.length);
|
||||
for (int i = 0, j = temp.length; j > 0; i++) {
|
||||
|
@ -252,7 +308,7 @@ abstract class _IntegerImplementation {
|
|||
// Integer division, rounding up, to find number of _digits.
|
||||
length += (value.bitLength + bitsPerDigit - 1) ~/ bitsPerDigit;
|
||||
_OneByteString string = _OneByteString._allocate(length);
|
||||
string._setAt(0, 0x2d); // '-'. Is overwritten if not negative.
|
||||
string._setAt(0, 0x2d); // '-'. Is overwritten if not negative.
|
||||
var mask = radix - 1;
|
||||
do {
|
||||
string._setAt(--length, _digits.codeUnitAt(value & mask));
|
||||
|
@ -310,10 +366,7 @@ abstract class _IntegerImplementation {
|
|||
final bool ac = x.isEven;
|
||||
int u = x;
|
||||
int v = y;
|
||||
int a = 1,
|
||||
b = 0,
|
||||
c = 0,
|
||||
d = 1;
|
||||
int a = 1, b = 0, c = 0, d = 1;
|
||||
do {
|
||||
while (u.isEven) {
|
||||
u >>= 1;
|
||||
|
@ -403,8 +456,7 @@ abstract class _IntegerImplementation {
|
|||
|
||||
class _Smi extends _IntegerImplementation implements int {
|
||||
factory _Smi._uninstantiable() {
|
||||
throw new UnsupportedError(
|
||||
"_Smi can only be allocated by the VM");
|
||||
throw new UnsupportedError("_Smi can only be allocated by the VM");
|
||||
}
|
||||
int get hashCode => this;
|
||||
int get _identityHashCode => this;
|
||||
|
@ -424,63 +476,63 @@ class _Smi extends _IntegerImplementation implements int {
|
|||
* `_digitTable[n * 2]` and `_digitTable[n * 2 + 1]`.
|
||||
*/
|
||||
static const _digitTable = const [
|
||||
0x30, 0x30, 0x30, 0x31, 0x30, 0x32, 0x30, 0x33,
|
||||
0x30, 0x34, 0x30, 0x35, 0x30, 0x36, 0x30, 0x37,
|
||||
0x30, 0x38, 0x30, 0x39, 0x31, 0x30, 0x31, 0x31,
|
||||
0x31, 0x32, 0x31, 0x33, 0x31, 0x34, 0x31, 0x35,
|
||||
0x31, 0x36, 0x31, 0x37, 0x31, 0x38, 0x31, 0x39,
|
||||
0x32, 0x30, 0x32, 0x31, 0x32, 0x32, 0x32, 0x33,
|
||||
0x32, 0x34, 0x32, 0x35, 0x32, 0x36, 0x32, 0x37,
|
||||
0x32, 0x38, 0x32, 0x39, 0x33, 0x30, 0x33, 0x31,
|
||||
0x33, 0x32, 0x33, 0x33, 0x33, 0x34, 0x33, 0x35,
|
||||
0x33, 0x36, 0x33, 0x37, 0x33, 0x38, 0x33, 0x39,
|
||||
0x34, 0x30, 0x34, 0x31, 0x34, 0x32, 0x34, 0x33,
|
||||
0x34, 0x34, 0x34, 0x35, 0x34, 0x36, 0x34, 0x37,
|
||||
0x34, 0x38, 0x34, 0x39, 0x35, 0x30, 0x35, 0x31,
|
||||
0x35, 0x32, 0x35, 0x33, 0x35, 0x34, 0x35, 0x35,
|
||||
0x35, 0x36, 0x35, 0x37, 0x35, 0x38, 0x35, 0x39,
|
||||
0x36, 0x30, 0x36, 0x31, 0x36, 0x32, 0x36, 0x33,
|
||||
0x36, 0x34, 0x36, 0x35, 0x36, 0x36, 0x36, 0x37,
|
||||
0x36, 0x38, 0x36, 0x39, 0x37, 0x30, 0x37, 0x31,
|
||||
0x37, 0x32, 0x37, 0x33, 0x37, 0x34, 0x37, 0x35,
|
||||
0x37, 0x36, 0x37, 0x37, 0x37, 0x38, 0x37, 0x39,
|
||||
0x38, 0x30, 0x38, 0x31, 0x38, 0x32, 0x38, 0x33,
|
||||
0x38, 0x34, 0x38, 0x35, 0x38, 0x36, 0x38, 0x37,
|
||||
0x38, 0x38, 0x38, 0x39, 0x39, 0x30, 0x39, 0x31,
|
||||
0x39, 0x32, 0x39, 0x33, 0x39, 0x34, 0x39, 0x35,
|
||||
0x39, 0x36, 0x39, 0x37, 0x39, 0x38, 0x39, 0x39
|
||||
0x30, 0x30, 0x30, 0x31, 0x30, 0x32, 0x30, 0x33, //
|
||||
0x30, 0x34, 0x30, 0x35, 0x30, 0x36, 0x30, 0x37, //
|
||||
0x30, 0x38, 0x30, 0x39, 0x31, 0x30, 0x31, 0x31, //
|
||||
0x31, 0x32, 0x31, 0x33, 0x31, 0x34, 0x31, 0x35, //
|
||||
0x31, 0x36, 0x31, 0x37, 0x31, 0x38, 0x31, 0x39, //
|
||||
0x32, 0x30, 0x32, 0x31, 0x32, 0x32, 0x32, 0x33, //
|
||||
0x32, 0x34, 0x32, 0x35, 0x32, 0x36, 0x32, 0x37, //
|
||||
0x32, 0x38, 0x32, 0x39, 0x33, 0x30, 0x33, 0x31, //
|
||||
0x33, 0x32, 0x33, 0x33, 0x33, 0x34, 0x33, 0x35, //
|
||||
0x33, 0x36, 0x33, 0x37, 0x33, 0x38, 0x33, 0x39, //
|
||||
0x34, 0x30, 0x34, 0x31, 0x34, 0x32, 0x34, 0x33, //
|
||||
0x34, 0x34, 0x34, 0x35, 0x34, 0x36, 0x34, 0x37, //
|
||||
0x34, 0x38, 0x34, 0x39, 0x35, 0x30, 0x35, 0x31, //
|
||||
0x35, 0x32, 0x35, 0x33, 0x35, 0x34, 0x35, 0x35, //
|
||||
0x35, 0x36, 0x35, 0x37, 0x35, 0x38, 0x35, 0x39, //
|
||||
0x36, 0x30, 0x36, 0x31, 0x36, 0x32, 0x36, 0x33, //
|
||||
0x36, 0x34, 0x36, 0x35, 0x36, 0x36, 0x36, 0x37, //
|
||||
0x36, 0x38, 0x36, 0x39, 0x37, 0x30, 0x37, 0x31, //
|
||||
0x37, 0x32, 0x37, 0x33, 0x37, 0x34, 0x37, 0x35, //
|
||||
0x37, 0x36, 0x37, 0x37, 0x37, 0x38, 0x37, 0x39, //
|
||||
0x38, 0x30, 0x38, 0x31, 0x38, 0x32, 0x38, 0x33, //
|
||||
0x38, 0x34, 0x38, 0x35, 0x38, 0x36, 0x38, 0x37, //
|
||||
0x38, 0x38, 0x38, 0x39, 0x39, 0x30, 0x39, 0x31, //
|
||||
0x39, 0x32, 0x39, 0x33, 0x39, 0x34, 0x39, 0x35, //
|
||||
0x39, 0x36, 0x39, 0x37, 0x39, 0x38, 0x39, 0x39, //
|
||||
];
|
||||
|
||||
/**
|
||||
* Result of int.toString for -99, -98, ..., 98, 99.
|
||||
*/
|
||||
static const _smallLookupTable = const [
|
||||
"-99", "-98", "-97", "-96", "-95", "-94", "-93", "-92", "-91", "-90",
|
||||
"-89", "-88", "-87", "-86", "-85", "-84", "-83", "-82", "-81", "-80",
|
||||
"-79", "-78", "-77", "-76", "-75", "-74", "-73", "-72", "-71", "-70",
|
||||
"-69", "-68", "-67", "-66", "-65", "-64", "-63", "-62", "-61", "-60",
|
||||
"-59", "-58", "-57", "-56", "-55", "-54", "-53", "-52", "-51", "-50",
|
||||
"-49", "-48", "-47", "-46", "-45", "-44", "-43", "-42", "-41", "-40",
|
||||
"-39", "-38", "-37", "-36", "-35", "-34", "-33", "-32", "-31", "-30",
|
||||
"-29", "-28", "-27", "-26", "-25", "-24", "-23", "-22", "-21", "-20",
|
||||
"-19", "-18", "-17", "-16", "-15", "-14", "-13", "-12", "-11", "-10",
|
||||
"-9", "-8", "-7", "-6", "-5", "-4", "-3", "-2", "-1", "0",
|
||||
"1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
|
||||
"11", "12", "13", "14", "15", "16", "17", "18", "19", "20",
|
||||
"21", "22", "23", "24", "25", "26", "27", "28", "29", "30",
|
||||
"31", "32", "33", "34", "35", "36", "37", "38", "39", "40",
|
||||
"41", "42", "43", "44", "45", "46", "47", "48", "49", "50",
|
||||
"51", "52", "53", "54", "55", "56", "57", "58", "59", "60",
|
||||
"61", "62", "63", "64", "65", "66", "67", "68", "69", "70",
|
||||
"71", "72", "73", "74", "75", "76", "77", "78", "79", "80",
|
||||
"81", "82", "83", "84", "85", "86", "87", "88", "89", "90",
|
||||
"91", "92", "93", "94", "95", "96", "97", "98", "99"
|
||||
"-99", "-98", "-97", "-96", "-95", "-94", "-93", "-92", "-91", "-90", //
|
||||
"-89", "-88", "-87", "-86", "-85", "-84", "-83", "-82", "-81", "-80", //
|
||||
"-79", "-78", "-77", "-76", "-75", "-74", "-73", "-72", "-71", "-70", //
|
||||
"-69", "-68", "-67", "-66", "-65", "-64", "-63", "-62", "-61", "-60", //
|
||||
"-59", "-58", "-57", "-56", "-55", "-54", "-53", "-52", "-51", "-50", //
|
||||
"-49", "-48", "-47", "-46", "-45", "-44", "-43", "-42", "-41", "-40", //
|
||||
"-39", "-38", "-37", "-36", "-35", "-34", "-33", "-32", "-31", "-30", //
|
||||
"-29", "-28", "-27", "-26", "-25", "-24", "-23", "-22", "-21", "-20", //
|
||||
"-19", "-18", "-17", "-16", "-15", "-14", "-13", "-12", "-11", "-10", //
|
||||
"-9", "-8", "-7", "-6", "-5", "-4", "-3", "-2", "-1", "0", //
|
||||
"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", //
|
||||
"11", "12", "13", "14", "15", "16", "17", "18", "19", "20", //
|
||||
"21", "22", "23", "24", "25", "26", "27", "28", "29", "30", //
|
||||
"31", "32", "33", "34", "35", "36", "37", "38", "39", "40", //
|
||||
"41", "42", "43", "44", "45", "46", "47", "48", "49", "50", //
|
||||
"51", "52", "53", "54", "55", "56", "57", "58", "59", "60", //
|
||||
"61", "62", "63", "64", "65", "66", "67", "68", "69", "70", //
|
||||
"71", "72", "73", "74", "75", "76", "77", "78", "79", "80", //
|
||||
"81", "82", "83", "84", "85", "86", "87", "88", "89", "90", //
|
||||
"91", "92", "93", "94", "95", "96", "97", "98", "99" //
|
||||
];
|
||||
|
||||
// Powers of 10 above 1000000 are indistinguishable by eye.
|
||||
static const int _POW_10_7 = 10000000;
|
||||
static const int _POW_10_8 = 100000000;
|
||||
static const int _POW_10_9 = 1000000000;
|
||||
static const int _POW_10_7 = 10000000;
|
||||
static const int _POW_10_8 = 100000000;
|
||||
static const int _POW_10_9 = 1000000000;
|
||||
|
||||
// Find the number of decimal digits in a positive smi.
|
||||
// Never called with numbers < 100. These are handled before calling.
|
||||
|
@ -565,20 +617,21 @@ class _Smi extends _IntegerImplementation implements int {
|
|||
// Character code for '0'.
|
||||
const int DIGIT_ZERO = 0x30;
|
||||
if (negSmi > -10) {
|
||||
return _OneByteString._allocate(2).._setAt(0, MINUS_SIGN)
|
||||
.._setAt(1, DIGIT_ZERO - negSmi);
|
||||
return _OneByteString._allocate(2)
|
||||
.._setAt(0, MINUS_SIGN)
|
||||
.._setAt(1, DIGIT_ZERO - negSmi);
|
||||
}
|
||||
if (negSmi > -100) {
|
||||
int digitIndex = 2 * -negSmi;
|
||||
return _OneByteString._allocate(3)
|
||||
.._setAt(0, MINUS_SIGN)
|
||||
.._setAt(1, _digitTable[digitIndex])
|
||||
.._setAt(2, _digitTable[digitIndex + 1]);
|
||||
.._setAt(0, MINUS_SIGN)
|
||||
.._setAt(1, _digitTable[digitIndex])
|
||||
.._setAt(2, _digitTable[digitIndex + 1]);
|
||||
}
|
||||
// Number of digits, not including minus.
|
||||
int digitCount = _negativeBase10Length(negSmi);
|
||||
_OneByteString result = _OneByteString._allocate(digitCount + 1);
|
||||
result._setAt(0, MINUS_SIGN); // '-'.
|
||||
result._setAt(0, MINUS_SIGN); // '-'.
|
||||
int index = digitCount;
|
||||
do {
|
||||
var twoDigits = negSmi.remainder(100);
|
||||
|
@ -603,8 +656,7 @@ class _Smi extends _IntegerImplementation implements int {
|
|||
// Represents integers that cannot be represented by Smi but fit into 64bits.
|
||||
class _Mint extends _IntegerImplementation implements int {
|
||||
factory _Mint._uninstantiable() {
|
||||
throw new UnsupportedError(
|
||||
"_Mint can only be allocated by the VM");
|
||||
throw new UnsupportedError("_Mint can only be allocated by the VM");
|
||||
}
|
||||
int get hashCode => this;
|
||||
int get _identityHashCode => this;
|
||||
|
@ -621,5 +673,6 @@ class _Mint extends _IntegerImplementation implements int {
|
|||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int _shlFromInt(int other) native "Mint_shlFromInt";
|
||||
}
|
||||
|
|
|
@ -5,13 +5,12 @@
|
|||
|
||||
// VM implementation of int.
|
||||
|
||||
@patch class int {
|
||||
|
||||
@patch const factory int.fromEnvironment(String name,
|
||||
{int defaultValue})
|
||||
@patch
|
||||
class int {
|
||||
@patch
|
||||
const factory int.fromEnvironment(String name, {int defaultValue})
|
||||
native "Integer_fromEnvironment";
|
||||
|
||||
|
||||
static int _tryParseSmi(String str, int first, int last) {
|
||||
assert(first <= last);
|
||||
var ix = first;
|
||||
|
@ -20,14 +19,14 @@
|
|||
// Check for leading '+' or '-'.
|
||||
if ((c == 0x2b) || (c == 0x2d)) {
|
||||
ix++;
|
||||
sign = 0x2c - c; // -1 for '-', +1 for '+'.
|
||||
sign = 0x2c - c; // -1 for '-', +1 for '+'.
|
||||
if (ix > last) {
|
||||
return null; // Empty.
|
||||
return null; // Empty.
|
||||
}
|
||||
}
|
||||
var smiLimit = internal.is64Bit ? 18 : 9;
|
||||
if ((last - ix) >= smiLimit) {
|
||||
return null; // May not fit into a Smi.
|
||||
return null; // May not fit into a Smi.
|
||||
}
|
||||
var result = 0;
|
||||
for (int i = ix; i <= last; i++) {
|
||||
|
@ -40,9 +39,8 @@
|
|||
return sign * result;
|
||||
}
|
||||
|
||||
@patch static int parse(String source,
|
||||
{ int radix,
|
||||
int onError(String source) }) {
|
||||
@patch
|
||||
static int parse(String source, {int radix, int onError(String source)}) {
|
||||
if (source == null) throw new ArgumentError("The source must not be null");
|
||||
if (source.isEmpty) return _throwFormatException(onError, source, 0, radix);
|
||||
if (radix == null || radix == 10) {
|
||||
|
@ -66,7 +64,7 @@
|
|||
int first = source.codeUnitAt(start);
|
||||
int sign = 1;
|
||||
if (first == 0x2b /* + */ || first == 0x2d /* - */) {
|
||||
sign = 0x2c - first; // -1 if '-', +1 if '+'.
|
||||
sign = 0x2c - first; // -1 if '-', +1 if '+'.
|
||||
start++;
|
||||
if (start == end) {
|
||||
return _throwFormatException(onError, source, end, radix);
|
||||
|
@ -109,8 +107,8 @@
|
|||
throw new FormatException("Invalid radix-$radix number", source, index);
|
||||
}
|
||||
|
||||
static int _parseRadix(String source, int radix,
|
||||
int start, int end, int sign) {
|
||||
static int _parseRadix(
|
||||
String source, int radix, int start, int end, int sign) {
|
||||
int tableIndex = (radix - 2) * 4 + (internal.is64Bit ? 2 : 0);
|
||||
int blockSize = _PARSE_LIMITS[tableIndex];
|
||||
int length = end - start;
|
||||
|
@ -172,40 +170,40 @@
|
|||
// and magnitude of such a block (radix ** digit-count).
|
||||
// 32-bit limit/multiplier at (radix - 2)*4, 64-bit limit at (radix-2)*4+2
|
||||
static const _PARSE_LIMITS = const [
|
||||
30, 1073741824, 62, 4611686018427387904, /* radix: 2 */
|
||||
18, 387420489, 39, 4052555153018976267,
|
||||
15, 1073741824, 30, 1152921504606846976,
|
||||
12, 244140625, 26, 1490116119384765625, /* radix: 5 */
|
||||
11, 362797056, 23, 789730223053602816,
|
||||
10, 282475249, 22, 3909821048582988049,
|
||||
10, 1073741824, 20, 1152921504606846976,
|
||||
9, 387420489, 19, 1350851717672992089,
|
||||
9, 1000000000, 18, 1000000000000000000, /* radix: 10 */
|
||||
8, 214358881, 17, 505447028499293771,
|
||||
8, 429981696, 17, 2218611106740436992,
|
||||
8, 815730721, 16, 665416609183179841,
|
||||
7, 105413504, 16, 2177953337809371136,
|
||||
7, 170859375, 15, 437893890380859375, /* radix: 15 */
|
||||
7, 268435456, 15, 1152921504606846976,
|
||||
7, 410338673, 15, 2862423051509815793,
|
||||
7, 612220032, 14, 374813367582081024,
|
||||
7, 893871739, 14, 799006685782884121,
|
||||
6, 64000000, 14, 1638400000000000000, /* radix: 20 */
|
||||
6, 85766121, 14, 3243919932521508681,
|
||||
6, 113379904, 13, 282810057883082752,
|
||||
6, 148035889, 13, 504036361936467383,
|
||||
6, 191102976, 13, 876488338465357824,
|
||||
6, 244140625, 13, 1490116119384765625, /* radix: 25 */
|
||||
6, 308915776, 13, 2481152873203736576,
|
||||
6, 387420489, 13, 4052555153018976267,
|
||||
6, 481890304, 12, 232218265089212416,
|
||||
6, 594823321, 12, 353814783205469041,
|
||||
6, 729000000, 12, 531441000000000000, /* radix: 30 */
|
||||
6, 887503681, 12, 787662783788549761,
|
||||
6, 1073741824, 12, 1152921504606846976,
|
||||
5, 39135393, 12, 1667889514952984961,
|
||||
5, 45435424, 12, 2386420683693101056,
|
||||
5, 52521875, 12, 3379220508056640625, /* radix: 35 */
|
||||
5, 60466176, 11, 131621703842267136,
|
||||
30, 1073741824, 62, 4611686018427387904, // radix: 2
|
||||
18, 387420489, 39, 4052555153018976267,
|
||||
15, 1073741824, 30, 1152921504606846976,
|
||||
12, 244140625, 26, 1490116119384765625, // radix: 5
|
||||
11, 362797056, 23, 789730223053602816,
|
||||
10, 282475249, 22, 3909821048582988049,
|
||||
10, 1073741824, 20, 1152921504606846976,
|
||||
9, 387420489, 19, 1350851717672992089,
|
||||
9, 1000000000, 18, 1000000000000000000, // radix: 10
|
||||
8, 214358881, 17, 505447028499293771,
|
||||
8, 429981696, 17, 2218611106740436992,
|
||||
8, 815730721, 16, 665416609183179841,
|
||||
7, 105413504, 16, 2177953337809371136,
|
||||
7, 170859375, 15, 437893890380859375, // radix: 15
|
||||
7, 268435456, 15, 1152921504606846976,
|
||||
7, 410338673, 15, 2862423051509815793,
|
||||
7, 612220032, 14, 374813367582081024,
|
||||
7, 893871739, 14, 799006685782884121,
|
||||
6, 64000000, 14, 1638400000000000000, // radix: 20
|
||||
6, 85766121, 14, 3243919932521508681,
|
||||
6, 113379904, 13, 282810057883082752,
|
||||
6, 148035889, 13, 504036361936467383,
|
||||
6, 191102976, 13, 876488338465357824,
|
||||
6, 244140625, 13, 1490116119384765625, // radix: 25
|
||||
6, 308915776, 13, 2481152873203736576,
|
||||
6, 387420489, 13, 4052555153018976267,
|
||||
6, 481890304, 12, 232218265089212416,
|
||||
6, 594823321, 12, 353814783205469041,
|
||||
6, 729000000, 12, 531441000000000000, // radix: 30
|
||||
6, 887503681, 12, 787662783788549761,
|
||||
6, 1073741824, 12, 1152921504606846976,
|
||||
5, 39135393, 12, 1667889514952984961,
|
||||
5, 45435424, 12, 2386420683693101056,
|
||||
5, 52521875, 12, 3379220508056640625, // radix: 35
|
||||
5, 60466176, 11, 131621703842267136,
|
||||
];
|
||||
}
|
||||
|
|
|
@ -28,8 +28,8 @@ Symbol _computeQualifiedName(DeclarationMirror owner, Symbol simpleName) {
|
|||
return _s('${_n(owner.qualifiedName)}.${_n(simpleName)}');
|
||||
}
|
||||
|
||||
String _makeSignatureString(TypeMirror returnType,
|
||||
List<ParameterMirror> parameters) {
|
||||
String _makeSignatureString(
|
||||
TypeMirror returnType, List<ParameterMirror> parameters) {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
buf.write('(');
|
||||
bool found_optional_positional = false;
|
||||
|
@ -65,14 +65,11 @@ String _makeSignatureString(TypeMirror returnType,
|
|||
return buf.toString();
|
||||
}
|
||||
|
||||
SourceLocation _location(reflectee)
|
||||
native "DeclarationMirror_location";
|
||||
SourceLocation _location(reflectee) native "DeclarationMirror_location";
|
||||
|
||||
List _metadata(reflectee)
|
||||
native 'DeclarationMirror_metadata';
|
||||
List _metadata(reflectee) native 'DeclarationMirror_metadata';
|
||||
|
||||
bool _subtypeTest(Type a, Type b)
|
||||
native 'TypeMirror_subtypeTest';
|
||||
bool _subtypeTest(Type a, Type b) native 'TypeMirror_subtypeTest';
|
||||
|
||||
class _AccessorCacheAssociation {
|
||||
String key;
|
||||
|
@ -90,8 +87,8 @@ class _AccessorCache {
|
|||
List table;
|
||||
int shift;
|
||||
int mask;
|
||||
int capacity; // Max number of associations before we start evicting/growing.
|
||||
int size = 0; // Current number of associations.
|
||||
int capacity; // Max number of associations before we start evicting/growing.
|
||||
int size = 0; // Current number of associations.
|
||||
|
||||
/**
|
||||
* Create a cache whose capacity is 75% of 2^shift.
|
||||
|
@ -223,12 +220,13 @@ class _LocalMirrorSystem extends MirrorSystem {
|
|||
var _libraries;
|
||||
Map<Uri, LibraryMirror> get libraries {
|
||||
if ((_libraries == null) || _dirty) {
|
||||
_libraries = new Map<Uri, LibraryMirror>.fromIterable(
|
||||
_computeLibraries(), key: (e) => e.uri);
|
||||
_libraries = new Map<Uri, LibraryMirror>.fromIterable(_computeLibraries(),
|
||||
key: (e) => e.uri);
|
||||
_dirty = false;
|
||||
}
|
||||
return _libraries;
|
||||
}
|
||||
|
||||
static _computeLibraries() native "MirrorSystem_libraries";
|
||||
|
||||
var _isolate;
|
||||
|
@ -238,6 +236,7 @@ class _LocalMirrorSystem extends MirrorSystem {
|
|||
}
|
||||
return _isolate;
|
||||
}
|
||||
|
||||
static _computeIsolate() native "MirrorSystem_isolate";
|
||||
|
||||
String toString() => "MirrorSystem for isolate '${isolate.debugName}'";
|
||||
|
@ -279,12 +278,8 @@ class _SyntheticAccessor implements MethodMirror {
|
|||
final bool isTopLevel;
|
||||
final _target;
|
||||
|
||||
_SyntheticAccessor(this.owner,
|
||||
this.simpleName,
|
||||
this.isGetter,
|
||||
this.isStatic,
|
||||
this.isTopLevel,
|
||||
this._target);
|
||||
_SyntheticAccessor(this.owner, this.simpleName, this.isGetter, this.isStatic,
|
||||
this.isTopLevel, this._target);
|
||||
|
||||
bool get isSynthetic => true;
|
||||
bool get isRegularMethod => false;
|
||||
|
@ -343,9 +338,8 @@ abstract class _LocalObjectMirror extends _LocalMirror implements ObjectMirror {
|
|||
|
||||
_LocalObjectMirror(this._reflectee);
|
||||
|
||||
InstanceMirror invoke(Symbol memberName,
|
||||
List positionalArguments,
|
||||
[Map<Symbol, dynamic> namedArguments]) {
|
||||
InstanceMirror invoke(Symbol memberName, List positionalArguments,
|
||||
[Map<Symbol, dynamic> namedArguments]) {
|
||||
int numPositionalArguments = positionalArguments.length;
|
||||
int numNamedArguments = namedArguments != null ? namedArguments.length : 0;
|
||||
int numArguments = numPositionalArguments + numNamedArguments;
|
||||
|
@ -375,9 +369,10 @@ abstract class _LocalObjectMirror extends _LocalMirror implements ObjectMirror {
|
|||
|
||||
delegate(Invocation invocation) {
|
||||
if (invocation.isMethod) {
|
||||
return this.invoke(invocation.memberName,
|
||||
invocation.positionalArguments,
|
||||
invocation.namedArguments).reflectee;
|
||||
return this
|
||||
.invoke(invocation.memberName, invocation.positionalArguments,
|
||||
invocation.namedArguments)
|
||||
.reflectee;
|
||||
}
|
||||
if (invocation.isGetter) {
|
||||
return this.getField(invocation.memberName).reflectee;
|
||||
|
@ -395,7 +390,6 @@ abstract class _LocalObjectMirror extends _LocalMirror implements ObjectMirror {
|
|||
|
||||
class _LocalInstanceMirror extends _LocalObjectMirror
|
||||
implements InstanceMirror {
|
||||
|
||||
_LocalInstanceMirror(reflectee) : super(reflectee);
|
||||
|
||||
ClassMirror _type;
|
||||
|
@ -417,7 +411,7 @@ class _LocalInstanceMirror extends _LocalObjectMirror
|
|||
|
||||
bool operator ==(other) {
|
||||
return other is _LocalInstanceMirror &&
|
||||
identical(_reflectee, other._reflectee);
|
||||
identical(_reflectee, other._reflectee);
|
||||
}
|
||||
|
||||
int get hashCode {
|
||||
|
@ -433,7 +427,7 @@ class _LocalInstanceMirror extends _LocalObjectMirror
|
|||
var atPosition = unwrapped.indexOf('@');
|
||||
if (atPosition == -1) {
|
||||
// Public symbol.
|
||||
return _eval('(x) => x.$unwrapped', null);
|
||||
return _eval('(x) => x.$unwrapped', null);
|
||||
} else {
|
||||
// Private symbol.
|
||||
var withoutKey = unwrapped.substring(0, atPosition);
|
||||
|
@ -507,14 +501,13 @@ class _LocalInstanceMirror extends _LocalObjectMirror
|
|||
native "Mirrors_evalInLibraryWithPrivateKey";
|
||||
|
||||
// Override to include the receiver in the arguments.
|
||||
InstanceMirror invoke(Symbol memberName,
|
||||
List positionalArguments,
|
||||
[Map<Symbol, dynamic> namedArguments]) {
|
||||
int numPositionalArguments = positionalArguments.length + 1; // Receiver.
|
||||
InstanceMirror invoke(Symbol memberName, List positionalArguments,
|
||||
[Map<Symbol, dynamic> namedArguments]) {
|
||||
int numPositionalArguments = positionalArguments.length + 1; // Receiver.
|
||||
int numNamedArguments = namedArguments != null ? namedArguments.length : 0;
|
||||
int numArguments = numPositionalArguments + numNamedArguments;
|
||||
List arguments = new List(numArguments);
|
||||
arguments[0] = _reflectee; // Receiver.
|
||||
arguments[0] = _reflectee; // Receiver.
|
||||
arguments.setRange(1, numPositionalArguments, positionalArguments);
|
||||
List names = new List(numNamedArguments);
|
||||
int argumentIndex = numPositionalArguments;
|
||||
|
@ -532,14 +525,12 @@ class _LocalInstanceMirror extends _LocalObjectMirror
|
|||
_invoke(reflectee, functionName, arguments, argumentNames)
|
||||
native 'InstanceMirror_invoke';
|
||||
|
||||
_invokeGetter(reflectee, getterName)
|
||||
native 'InstanceMirror_invokeGetter';
|
||||
_invokeGetter(reflectee, getterName) native 'InstanceMirror_invokeGetter';
|
||||
|
||||
_invokeSetter(reflectee, setterName, value)
|
||||
native 'InstanceMirror_invokeSetter';
|
||||
|
||||
static _computeType(reflectee)
|
||||
native 'InstanceMirror_computeType';
|
||||
static _computeType(reflectee) native 'InstanceMirror_computeType';
|
||||
}
|
||||
|
||||
class _LocalClosureMirror extends _LocalInstanceMirror
|
||||
|
@ -555,18 +546,16 @@ class _LocalClosureMirror extends _LocalInstanceMirror
|
|||
}
|
||||
|
||||
InstanceMirror apply(List<Object> positionalArguments,
|
||||
[Map<Symbol, Object> namedArguments]) {
|
||||
[Map<Symbol, Object> namedArguments]) {
|
||||
return this.invoke(#call, positionalArguments, namedArguments);
|
||||
}
|
||||
|
||||
String toString() => "ClosureMirror on '${Error.safeToString(_reflectee)}'";
|
||||
|
||||
static _computeFunction(reflectee)
|
||||
native 'ClosureMirror_function';
|
||||
static _computeFunction(reflectee) native 'ClosureMirror_function';
|
||||
}
|
||||
|
||||
class _LocalClassMirror extends _LocalObjectMirror
|
||||
implements ClassMirror {
|
||||
class _LocalClassMirror extends _LocalObjectMirror implements ClassMirror {
|
||||
final Type _reflectedType;
|
||||
Symbol _simpleName;
|
||||
DeclarationMirror _owner;
|
||||
|
@ -577,21 +566,21 @@ class _LocalClassMirror extends _LocalObjectMirror
|
|||
final bool isEnum;
|
||||
Type _instantiator;
|
||||
|
||||
_LocalClassMirror(reflectee,
|
||||
reflectedType,
|
||||
String simpleName,
|
||||
this._owner,
|
||||
this.isAbstract,
|
||||
this._isGeneric,
|
||||
this._isMixinAlias,
|
||||
this._isGenericDeclaration,
|
||||
this.isEnum)
|
||||
_LocalClassMirror(
|
||||
reflectee,
|
||||
reflectedType,
|
||||
String simpleName,
|
||||
this._owner,
|
||||
this.isAbstract,
|
||||
this._isGeneric,
|
||||
this._isMixinAlias,
|
||||
this._isGenericDeclaration,
|
||||
this.isEnum)
|
||||
: this._simpleName = _s(simpleName),
|
||||
this._reflectedType = reflectedType,
|
||||
this._instantiator = reflectedType,
|
||||
super(reflectee);
|
||||
|
||||
|
||||
bool get hasReflectedType => !_isGenericDeclaration;
|
||||
Type get reflectedType {
|
||||
if (!hasReflectedType) {
|
||||
|
@ -603,7 +592,7 @@ class _LocalClassMirror extends _LocalObjectMirror
|
|||
|
||||
Symbol get simpleName {
|
||||
// All but anonymous mixin applications have their name set at construction.
|
||||
if(_simpleName == null) {
|
||||
if (_simpleName == null) {
|
||||
_simpleName = this._mixinApplicationName;
|
||||
}
|
||||
return _simpleName;
|
||||
|
@ -648,6 +637,7 @@ class _LocalClassMirror extends _LocalObjectMirror
|
|||
}
|
||||
return _trueSuperclassField;
|
||||
}
|
||||
|
||||
ClassMirror get superclass {
|
||||
return _isMixinAlias ? _trueSuperclass._trueSuperclass : _trueSuperclass;
|
||||
}
|
||||
|
@ -671,10 +661,9 @@ class _LocalClassMirror extends _LocalObjectMirror
|
|||
mixins.add(klass.mixin);
|
||||
klass = klass.superclass;
|
||||
}
|
||||
return _s(
|
||||
_n(klass.qualifiedName)
|
||||
+ ' with '
|
||||
+ mixins.reversed.map((m)=>_n(m.qualifiedName)).join(', '));
|
||||
return _s(_n(klass.qualifiedName) +
|
||||
' with ' +
|
||||
mixins.reversed.map((m) => _n(m.qualifiedName)).join(', '));
|
||||
}
|
||||
|
||||
var _mixin;
|
||||
|
@ -685,8 +674,8 @@ class _LocalClassMirror extends _LocalObjectMirror
|
|||
_trueSuperclass._reflectedType, _instantiator);
|
||||
_mixin = reflectType(mixinType);
|
||||
} else {
|
||||
Type mixinType = _nativeMixinInstantiated(_reflectedType,
|
||||
_instantiator);
|
||||
Type mixinType =
|
||||
_nativeMixinInstantiated(_reflectedType, _instantiator);
|
||||
if (mixinType == null) {
|
||||
// The reflectee is not a mixin application.
|
||||
_mixin = this;
|
||||
|
@ -731,14 +720,16 @@ class _LocalClassMirror extends _LocalObjectMirror
|
|||
result.addAll(superclass.instanceMembers);
|
||||
}
|
||||
declarations.values.forEach((decl) {
|
||||
if (decl is MethodMirror && !decl.isStatic &&
|
||||
!decl.isConstructor && !decl.isAbstract) {
|
||||
if (decl is MethodMirror &&
|
||||
!decl.isStatic &&
|
||||
!decl.isConstructor &&
|
||||
!decl.isAbstract) {
|
||||
result[decl.simpleName] = decl;
|
||||
}
|
||||
if (decl is VariableMirror && !decl.isStatic) {
|
||||
var getterName = decl.simpleName;
|
||||
result[getterName] =
|
||||
new _SyntheticAccessor(this, getterName, true, false, false, decl);
|
||||
result[getterName] = new _SyntheticAccessor(
|
||||
this, getterName, true, false, false, decl);
|
||||
if (!decl.isFinal) {
|
||||
var setterName = _asSetter(decl.simpleName, this.owner);
|
||||
result[setterName] = new _SyntheticAccessor(
|
||||
|
@ -759,8 +750,8 @@ class _LocalClassMirror extends _LocalObjectMirror
|
|||
var decls = new Map<Symbol, DeclarationMirror>();
|
||||
|
||||
var whoseMembers = _isMixinAlias ? _trueSuperclass : this;
|
||||
var members = mixin._computeMembers(_instantiator,
|
||||
whoseMembers.mixin._reflectee);
|
||||
var members =
|
||||
mixin._computeMembers(_instantiator, whoseMembers.mixin._reflectee);
|
||||
for (var member in members) {
|
||||
decls[member.simpleName] = member;
|
||||
}
|
||||
|
@ -781,8 +772,8 @@ class _LocalClassMirror extends _LocalObjectMirror
|
|||
}
|
||||
|
||||
bool get _isAnonymousMixinApplication {
|
||||
if (_isMixinAlias) return false; // Named mixin application.
|
||||
if (mixin == this) return false; // Not a mixin application.
|
||||
if (_isMixinAlias) return false; // Named mixin application.
|
||||
if (mixin == this) return false; // Not a mixin application.
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -796,8 +787,7 @@ class _LocalClassMirror extends _LocalObjectMirror
|
|||
ClassMirror owner = originalDeclaration;
|
||||
var mirror;
|
||||
for (var i = 0; i < params.length; i += 2) {
|
||||
mirror = new _LocalTypeVariableMirror(
|
||||
params[i + 1], params[i], owner);
|
||||
mirror = new _LocalTypeVariableMirror(params[i + 1], params[i], owner);
|
||||
_typeVariables.add(mirror);
|
||||
}
|
||||
_typeVariables = new UnmodifiableListView(_typeVariables);
|
||||
|
@ -807,8 +797,8 @@ class _LocalClassMirror extends _LocalObjectMirror
|
|||
|
||||
List<TypeMirror> _typeArguments = null;
|
||||
List<TypeMirror> get typeArguments {
|
||||
if(_typeArguments == null) {
|
||||
if(_isGenericDeclaration || _isAnonymousMixinApplication) {
|
||||
if (_typeArguments == null) {
|
||||
if (_isGenericDeclaration || _isAnonymousMixinApplication) {
|
||||
_typeArguments = _emptyList;
|
||||
} else {
|
||||
_typeArguments =
|
||||
|
@ -830,9 +820,8 @@ class _LocalClassMirror extends _LocalObjectMirror
|
|||
|
||||
String toString() => "ClassMirror on '${MirrorSystem.getName(simpleName)}'";
|
||||
|
||||
InstanceMirror newInstance(Symbol constructorName,
|
||||
List positionalArguments,
|
||||
[Map<Symbol, dynamic> namedArguments]) {
|
||||
InstanceMirror newInstance(Symbol constructorName, List positionalArguments,
|
||||
[Map<Symbol, dynamic> namedArguments]) {
|
||||
// Native code will add the 1 or 2 implicit arguments depending on whether
|
||||
// we end up invoking a factory or constructor respectively.
|
||||
int numPositionalArguments = positionalArguments.length;
|
||||
|
@ -850,11 +839,8 @@ class _LocalClassMirror extends _LocalObjectMirror
|
|||
});
|
||||
}
|
||||
|
||||
return reflect(_invokeConstructor(_reflectee,
|
||||
_reflectedType,
|
||||
_n(constructorName),
|
||||
arguments,
|
||||
names));
|
||||
return reflect(_invokeConstructor(
|
||||
_reflectee, _reflectedType, _n(constructorName), arguments, names));
|
||||
}
|
||||
|
||||
List<InstanceMirror> get metadata {
|
||||
|
@ -865,9 +851,9 @@ class _LocalClassMirror extends _LocalObjectMirror
|
|||
|
||||
bool operator ==(other) {
|
||||
return this.runtimeType == other.runtimeType &&
|
||||
this._reflectee == other._reflectee &&
|
||||
this._reflectedType == other._reflectedType &&
|
||||
this._isGenericDeclaration == other._isGenericDeclaration;
|
||||
this._reflectee == other._reflectee &&
|
||||
this._reflectedType == other._reflectedType &&
|
||||
this._isGenericDeclaration == other._isGenericDeclaration;
|
||||
}
|
||||
|
||||
int get hashCode => simpleName.hashCode;
|
||||
|
@ -881,8 +867,8 @@ class _LocalClassMirror extends _LocalObjectMirror
|
|||
bool isAssignableTo(TypeMirror other) {
|
||||
if (other == currentMirrorSystem().dynamicType) return true;
|
||||
if (other == currentMirrorSystem().voidType) return false;
|
||||
return _subtypeTest(_reflectedType, other._reflectedType)
|
||||
|| _subtypeTest(other._reflectedType, _reflectedType);
|
||||
return _subtypeTest(_reflectedType, other._reflectedType) ||
|
||||
_subtypeTest(other._reflectedType, _reflectedType);
|
||||
}
|
||||
|
||||
bool isSubclassOf(ClassMirror other) {
|
||||
|
@ -897,29 +883,24 @@ class _LocalClassMirror extends _LocalObjectMirror
|
|||
return false;
|
||||
}
|
||||
|
||||
static _libraryUri(reflectee)
|
||||
native "ClassMirror_libraryUri";
|
||||
static _libraryUri(reflectee) native "ClassMirror_libraryUri";
|
||||
|
||||
static _supertype(reflectedType)
|
||||
native "ClassMirror_supertype";
|
||||
static _supertype(reflectedType) native "ClassMirror_supertype";
|
||||
|
||||
static _supertypeInstantiated(reflectedType)
|
||||
native "ClassMirror_supertype_instantiated";
|
||||
|
||||
static _nativeInterfaces(reflectedType)
|
||||
native "ClassMirror_interfaces";
|
||||
static _nativeInterfaces(reflectedType) native "ClassMirror_interfaces";
|
||||
|
||||
static _nativeInterfacesInstantiated(reflectedType)
|
||||
native "ClassMirror_interfaces_instantiated";
|
||||
|
||||
static _nativeMixin(reflectedType)
|
||||
native "ClassMirror_mixin";
|
||||
static _nativeMixin(reflectedType) native "ClassMirror_mixin";
|
||||
|
||||
static _nativeMixinInstantiated(reflectedType, instantiator)
|
||||
native "ClassMirror_mixin_instantiated";
|
||||
|
||||
_computeMembers(reflectee, instantiator)
|
||||
native "ClassMirror_members";
|
||||
_computeMembers(reflectee, instantiator) native "ClassMirror_members";
|
||||
|
||||
_computeConstructors(reflectee, instantiator)
|
||||
native "ClassMirror_constructors";
|
||||
|
@ -927,27 +908,25 @@ class _LocalClassMirror extends _LocalObjectMirror
|
|||
_invoke(reflectee, memberName, arguments, argumentNames)
|
||||
native 'ClassMirror_invoke';
|
||||
|
||||
_invokeGetter(reflectee, getterName)
|
||||
native 'ClassMirror_invokeGetter';
|
||||
_invokeGetter(reflectee, getterName) native 'ClassMirror_invokeGetter';
|
||||
|
||||
_invokeSetter(reflectee, setterName, value)
|
||||
native 'ClassMirror_invokeSetter';
|
||||
_invokeSetter(reflectee, setterName, value) native 'ClassMirror_invokeSetter';
|
||||
|
||||
static _invokeConstructor(reflectee, type, constructorName, arguments, argumentNames)
|
||||
native 'ClassMirror_invokeConstructor';
|
||||
static _invokeConstructor(reflectee, type, constructorName, arguments,
|
||||
argumentNames) native 'ClassMirror_invokeConstructor';
|
||||
|
||||
static _ClassMirror_type_variables(reflectee)
|
||||
native "ClassMirror_type_variables";
|
||||
|
||||
static _computeTypeArguments(reflectee)
|
||||
native "ClassMirror_type_arguments";
|
||||
static _computeTypeArguments(reflectee) native "ClassMirror_type_arguments";
|
||||
}
|
||||
|
||||
class _LocalFunctionTypeMirror extends _LocalClassMirror
|
||||
implements FunctionTypeMirror {
|
||||
final _functionReflectee;
|
||||
_LocalFunctionTypeMirror(reflectee, this._functionReflectee, reflectedType)
|
||||
: super(reflectee, reflectedType, null, null, false, false, false, false, false);
|
||||
: super(reflectee, reflectedType, null, null, false, false, false, false,
|
||||
false);
|
||||
|
||||
bool get _isAnonymousMixinApplication => false;
|
||||
|
||||
|
@ -1036,7 +1015,7 @@ abstract class _LocalDeclarationMirror extends _LocalMirror
|
|||
|
||||
bool operator ==(other) {
|
||||
return this.runtimeType == other.runtimeType &&
|
||||
this._reflectee == other._reflectee;
|
||||
this._reflectee == other._reflectee;
|
||||
}
|
||||
|
||||
int get hashCode => simpleName.hashCode;
|
||||
|
@ -1044,9 +1023,7 @@ abstract class _LocalDeclarationMirror extends _LocalMirror
|
|||
|
||||
class _LocalTypeVariableMirror extends _LocalDeclarationMirror
|
||||
implements TypeVariableMirror {
|
||||
_LocalTypeVariableMirror(reflectee,
|
||||
String simpleName,
|
||||
this._owner)
|
||||
_LocalTypeVariableMirror(reflectee, String simpleName, this._owner)
|
||||
: super(reflectee, _s(simpleName));
|
||||
|
||||
DeclarationMirror _owner;
|
||||
|
@ -1072,6 +1049,7 @@ class _LocalTypeVariableMirror extends _LocalDeclarationMirror
|
|||
Type get reflectedType {
|
||||
throw new UnsupportedError('Type variables have no reflected type');
|
||||
}
|
||||
|
||||
Type get _reflectedType => _reflectee;
|
||||
|
||||
List<TypeVariableMirror> get typeVariables => _emptyList;
|
||||
|
@ -1083,10 +1061,11 @@ class _LocalTypeVariableMirror extends _LocalDeclarationMirror
|
|||
String toString() => "TypeVariableMirror on '${_n(simpleName)}'";
|
||||
|
||||
operator ==(other) {
|
||||
return other is TypeVariableMirror
|
||||
&& simpleName == other.simpleName
|
||||
&& owner == other.owner;
|
||||
return other is TypeVariableMirror &&
|
||||
simpleName == other.simpleName &&
|
||||
owner == other.owner;
|
||||
}
|
||||
|
||||
int get hashCode => simpleName.hashCode;
|
||||
|
||||
bool isSubtypeOf(TypeMirror other) {
|
||||
|
@ -1098,8 +1077,8 @@ class _LocalTypeVariableMirror extends _LocalDeclarationMirror
|
|||
bool isAssignableTo(TypeMirror other) {
|
||||
if (other == currentMirrorSystem().dynamicType) return true;
|
||||
if (other == currentMirrorSystem().voidType) return false;
|
||||
return _subtypeTest(_reflectedType, other._reflectedType)
|
||||
|| _subtypeTest(other._reflectedType, _reflectedType);
|
||||
return _subtypeTest(_reflectedType, other._reflectedType) ||
|
||||
_subtypeTest(other._reflectedType, _reflectedType);
|
||||
}
|
||||
|
||||
static DeclarationMirror _TypeVariableMirror_owner(reflectee)
|
||||
|
@ -1109,19 +1088,14 @@ class _LocalTypeVariableMirror extends _LocalDeclarationMirror
|
|||
native "TypeVariableMirror_upper_bound";
|
||||
}
|
||||
|
||||
|
||||
class _LocalTypedefMirror extends _LocalDeclarationMirror
|
||||
implements TypedefMirror {
|
||||
final Type _reflectedType;
|
||||
final bool _isGeneric;
|
||||
final bool _isGenericDeclaration;
|
||||
|
||||
_LocalTypedefMirror(reflectee,
|
||||
this._reflectedType,
|
||||
String simpleName,
|
||||
this._isGeneric,
|
||||
this._isGenericDeclaration,
|
||||
this._owner)
|
||||
_LocalTypedefMirror(reflectee, this._reflectedType, String simpleName,
|
||||
this._isGeneric, this._isGenericDeclaration, this._owner)
|
||||
: super(reflectee, _s(simpleName));
|
||||
|
||||
bool get isTopLevel => true;
|
||||
|
@ -1171,8 +1145,7 @@ class _LocalTypedefMirror extends _LocalDeclarationMirror
|
|||
TypedefMirror owner = originalDeclaration;
|
||||
var mirror;
|
||||
for (var i = 0; i < params.length; i += 2) {
|
||||
mirror = new _LocalTypeVariableMirror(
|
||||
params[i + 1], params[i], owner);
|
||||
mirror = new _LocalTypeVariableMirror(params[i + 1], params[i], owner);
|
||||
_typeVariables.add(mirror);
|
||||
}
|
||||
}
|
||||
|
@ -1181,8 +1154,8 @@ class _LocalTypedefMirror extends _LocalDeclarationMirror
|
|||
|
||||
List<TypeMirror> _typeArguments = null;
|
||||
List<TypeMirror> get typeArguments {
|
||||
if(_typeArguments == null) {
|
||||
if(_isGenericDeclaration) {
|
||||
if (_typeArguments == null) {
|
||||
if (_isGenericDeclaration) {
|
||||
_typeArguments = _emptyList;
|
||||
} else {
|
||||
_typeArguments = new UnmodifiableListView(
|
||||
|
@ -1203,15 +1176,13 @@ class _LocalTypedefMirror extends _LocalDeclarationMirror
|
|||
bool isAssignableTo(TypeMirror other) {
|
||||
if (other == currentMirrorSystem().dynamicType) return true;
|
||||
if (other == currentMirrorSystem().voidType) return false;
|
||||
return _subtypeTest(_reflectedType, other._reflectedType)
|
||||
|| _subtypeTest(other._reflectedType, _reflectedType);
|
||||
return _subtypeTest(_reflectedType, other._reflectedType) ||
|
||||
_subtypeTest(other._reflectedType, _reflectedType);
|
||||
}
|
||||
|
||||
static _nativeReferent(reflectedType)
|
||||
native "TypedefMirror_referent";
|
||||
static _nativeReferent(reflectedType) native "TypedefMirror_referent";
|
||||
|
||||
static _nativeDeclaration(reflectedType)
|
||||
native "TypedefMirror_declaration";
|
||||
static _nativeDeclaration(reflectedType) native "TypedefMirror_declaration";
|
||||
}
|
||||
|
||||
Symbol _asSetter(Symbol getter, LibraryMirror library) {
|
||||
|
@ -1223,9 +1194,7 @@ class _LocalLibraryMirror extends _LocalObjectMirror implements LibraryMirror {
|
|||
final Symbol simpleName;
|
||||
final Uri uri;
|
||||
|
||||
_LocalLibraryMirror(reflectee,
|
||||
String simpleName,
|
||||
String url)
|
||||
_LocalLibraryMirror(reflectee, String simpleName, String url)
|
||||
: this.simpleName = _s(simpleName),
|
||||
this.uri = Uri.parse(url),
|
||||
super(reflectee);
|
||||
|
@ -1266,7 +1235,7 @@ class _LocalLibraryMirror extends _LocalObjectMirror implements LibraryMirror {
|
|||
|
||||
bool operator ==(other) {
|
||||
return this.runtimeType == other.runtimeType &&
|
||||
this._reflectee == other._reflectee;
|
||||
this._reflectee == other._reflectee;
|
||||
}
|
||||
|
||||
int get hashCode => simpleName.hashCode;
|
||||
|
@ -1281,24 +1250,21 @@ class _LocalLibraryMirror extends _LocalObjectMirror implements LibraryMirror {
|
|||
return _cachedLibraryDependencies;
|
||||
}
|
||||
|
||||
_libraryDependencies(reflectee)
|
||||
native 'LibraryMirror_libraryDependencies';
|
||||
_libraryDependencies(reflectee) native 'LibraryMirror_libraryDependencies';
|
||||
|
||||
_invoke(reflectee, memberName, arguments, argumentNames)
|
||||
native 'LibraryMirror_invoke';
|
||||
|
||||
_invokeGetter(reflectee, getterName)
|
||||
native 'LibraryMirror_invokeGetter';
|
||||
_invokeGetter(reflectee, getterName) native 'LibraryMirror_invokeGetter';
|
||||
|
||||
_invokeSetter(reflectee, setterName, value)
|
||||
native 'LibraryMirror_invokeSetter';
|
||||
|
||||
_computeMembers(reflectee)
|
||||
native "LibraryMirror_members";
|
||||
_computeMembers(reflectee) native "LibraryMirror_members";
|
||||
}
|
||||
|
||||
class _LocalLibraryDependencyMirror
|
||||
extends _LocalMirror implements LibraryDependencyMirror {
|
||||
class _LocalLibraryDependencyMirror extends _LocalMirror
|
||||
implements LibraryDependencyMirror {
|
||||
final LibraryMirror sourceLibrary;
|
||||
var _targetMirrorOrPrefix;
|
||||
final List<CombinatorMirror> combinators;
|
||||
|
@ -1307,13 +1273,14 @@ class _LocalLibraryDependencyMirror
|
|||
final bool isDeferred;
|
||||
final List<InstanceMirror> metadata;
|
||||
|
||||
_LocalLibraryDependencyMirror(this.sourceLibrary,
|
||||
this._targetMirrorOrPrefix,
|
||||
this.combinators,
|
||||
prefixString,
|
||||
this.isImport,
|
||||
this.isDeferred,
|
||||
unwrappedMetadata)
|
||||
_LocalLibraryDependencyMirror(
|
||||
this.sourceLibrary,
|
||||
this._targetMirrorOrPrefix,
|
||||
this.combinators,
|
||||
prefixString,
|
||||
this.isImport,
|
||||
this.isDeferred,
|
||||
unwrappedMetadata)
|
||||
: prefix = _s(prefixString),
|
||||
metadata = new UnmodifiableListView(unwrappedMetadata.map(reflect));
|
||||
|
||||
|
@ -1359,12 +1326,8 @@ class _LocalMethodMirror extends _LocalDeclarationMirror
|
|||
final bool isStatic;
|
||||
final int _kindFlags;
|
||||
|
||||
_LocalMethodMirror(reflectee,
|
||||
String simpleName,
|
||||
this._owner,
|
||||
this._instantiator,
|
||||
this.isStatic,
|
||||
this._kindFlags)
|
||||
_LocalMethodMirror(reflectee, String simpleName, this._owner,
|
||||
this._instantiator, this.isStatic, this._kindFlags)
|
||||
: super(reflectee, _s(simpleName));
|
||||
|
||||
static const kAbstract = 0;
|
||||
|
@ -1378,18 +1341,23 @@ class _LocalMethodMirror extends _LocalDeclarationMirror
|
|||
static const kExternal = 8;
|
||||
|
||||
// These offsets much be kept in sync with those in mirrors.h.
|
||||
bool get isAbstract => 0 != (_kindFlags & (1 << kAbstract));
|
||||
bool get isGetter => 0 != (_kindFlags & (1 << kGetter));
|
||||
bool get isSetter => 0 != (_kindFlags & (1 << kSetter));
|
||||
bool get isConstructor => 0 != (_kindFlags & (1 << kConstructor));
|
||||
bool get isConstConstructor => 0 != (_kindFlags & (1 << kConstCtor));
|
||||
bool get isGenerativeConstructor => 0 != (_kindFlags & (1 << kGenerativeCtor));
|
||||
bool get isRedirectingConstructor => 0 != (_kindFlags & (1 << kRedirectingCtor));
|
||||
bool get isFactoryConstructor => 0 != (_kindFlags & (1 << kFactoryCtor));
|
||||
bool get isExternal => 0 != (_kindFlags & (1 << kExternal));
|
||||
bool get isAbstract => 0 != (_kindFlags & (1 << kAbstract));
|
||||
bool get isGetter => 0 != (_kindFlags & (1 << kGetter));
|
||||
bool get isSetter => 0 != (_kindFlags & (1 << kSetter));
|
||||
bool get isConstructor => 0 != (_kindFlags & (1 << kConstructor));
|
||||
bool get isConstConstructor => 0 != (_kindFlags & (1 << kConstCtor));
|
||||
bool get isGenerativeConstructor =>
|
||||
0 != (_kindFlags & (1 << kGenerativeCtor));
|
||||
bool get isRedirectingConstructor =>
|
||||
0 != (_kindFlags & (1 << kRedirectingCtor));
|
||||
bool get isFactoryConstructor => 0 != (_kindFlags & (1 << kFactoryCtor));
|
||||
bool get isExternal => 0 != (_kindFlags & (1 << kExternal));
|
||||
|
||||
static const _operators = const ["%", "&", "*", "+", "-", "/", "<", "<<",
|
||||
"<=", "==", ">", ">=", ">>", "[]", "[]=", "^", "|", "~", "unary-", "~/"];
|
||||
static const _operators = const [
|
||||
"%", "&", "*", "+", "-", "/", "<", "<<", //
|
||||
"<=", "==", ">", ">=", ">>", "[]", "[]=",
|
||||
"^", "|", "~", "unary-", "~/",
|
||||
];
|
||||
bool get isOperator => _operators.contains(_n(simpleName));
|
||||
|
||||
DeclarationMirror _owner;
|
||||
|
@ -1402,8 +1370,8 @@ class _LocalMethodMirror extends _LocalDeclarationMirror
|
|||
return _owner;
|
||||
}
|
||||
|
||||
bool get isPrivate => _n(simpleName).startsWith('_') ||
|
||||
_n(constructorName).startsWith('_');
|
||||
bool get isPrivate =>
|
||||
_n(simpleName).startsWith('_') || _n(constructorName).startsWith('_');
|
||||
|
||||
bool get isTopLevel => owner is LibraryMirror;
|
||||
bool get isSynthetic => false;
|
||||
|
@ -1414,8 +1382,8 @@ class _LocalMethodMirror extends _LocalDeclarationMirror
|
|||
if (isConstructor) {
|
||||
_returnType = owner;
|
||||
} else {
|
||||
_returnType = reflectType(
|
||||
_MethodMirror_return_type(_reflectee, _instantiator));
|
||||
_returnType =
|
||||
reflectType(_MethodMirror_return_type(_reflectee, _instantiator));
|
||||
}
|
||||
}
|
||||
return _returnType;
|
||||
|
@ -1476,8 +1444,7 @@ class _LocalMethodMirror extends _LocalDeclarationMirror
|
|||
List<ParameterMirror> _MethodMirror_parameters(reflectee)
|
||||
native "MethodMirror_parameters";
|
||||
|
||||
static String _MethodMirror_source(reflectee)
|
||||
native "MethodMirror_source";
|
||||
static String _MethodMirror_source(reflectee) native "MethodMirror_source";
|
||||
}
|
||||
|
||||
class _LocalVariableMirror extends _LocalDeclarationMirror
|
||||
|
@ -1487,13 +1454,8 @@ class _LocalVariableMirror extends _LocalDeclarationMirror
|
|||
final bool isFinal;
|
||||
final bool isConst;
|
||||
|
||||
_LocalVariableMirror(reflectee,
|
||||
String simpleName,
|
||||
this.owner,
|
||||
this._type,
|
||||
this.isStatic,
|
||||
this.isFinal,
|
||||
this.isConst)
|
||||
_LocalVariableMirror(reflectee, String simpleName, this.owner, this._type,
|
||||
this.isStatic, this.isFinal, this.isConst)
|
||||
: super(reflectee, _s(simpleName));
|
||||
|
||||
bool get isTopLevel => owner is LibraryMirror;
|
||||
|
@ -1505,12 +1467,13 @@ class _LocalVariableMirror extends _LocalDeclarationMirror
|
|||
TypeMirror _type;
|
||||
TypeMirror get type {
|
||||
if (_type == null) {
|
||||
_type = reflectType(_VariableMirror_type(_reflectee, _instantiator));
|
||||
_type = reflectType(_VariableMirror_type(_reflectee, _instantiator));
|
||||
}
|
||||
return _type;
|
||||
}
|
||||
|
||||
String toString() => "VariableMirror on '${MirrorSystem.getName(simpleName)}'";
|
||||
String toString() =>
|
||||
"VariableMirror on '${MirrorSystem.getName(simpleName)}'";
|
||||
|
||||
static _VariableMirror_type(reflectee, instantiator)
|
||||
native "VariableMirror_type";
|
||||
|
@ -1523,23 +1486,25 @@ class _LocalParameterMirror extends _LocalVariableMirror
|
|||
final bool isNamed;
|
||||
final List _unmirroredMetadata;
|
||||
|
||||
_LocalParameterMirror(reflectee,
|
||||
String simpleName,
|
||||
DeclarationMirror owner,
|
||||
this._position,
|
||||
this.isOptional,
|
||||
this.isNamed,
|
||||
bool isFinal,
|
||||
this._defaultValueReflectee,
|
||||
this._unmirroredMetadata)
|
||||
: super(reflectee,
|
||||
simpleName,
|
||||
owner,
|
||||
null, // We override the type.
|
||||
false, // isStatic does not apply.
|
||||
isFinal,
|
||||
false // Not const.
|
||||
);
|
||||
_LocalParameterMirror(
|
||||
reflectee,
|
||||
String simpleName,
|
||||
DeclarationMirror owner,
|
||||
this._position,
|
||||
this.isOptional,
|
||||
this.isNamed,
|
||||
bool isFinal,
|
||||
this._defaultValueReflectee,
|
||||
this._unmirroredMetadata)
|
||||
: super(
|
||||
reflectee,
|
||||
simpleName,
|
||||
owner,
|
||||
null, // We override the type.
|
||||
false, // isStatic does not apply.
|
||||
isFinal,
|
||||
false // Not const.
|
||||
);
|
||||
|
||||
Object _defaultValueReflectee;
|
||||
InstanceMirror _defaultValue;
|
||||
|
@ -1683,8 +1648,8 @@ class _Mirrors {
|
|||
|
||||
static Type _instantiateType(Type key, List<Type> typeArguments) {
|
||||
if (typeArguments.isEmpty) {
|
||||
throw new ArgumentError.value(
|
||||
typeArguments, 'typeArguments', 'Type arguments list cannot be empty.');
|
||||
throw new ArgumentError.value(typeArguments, 'typeArguments',
|
||||
'Type arguments list cannot be empty.');
|
||||
}
|
||||
return instantiateGenericType(key, typeArguments.toList(growable: false));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue