Files
sdk/tests/utils/dummy_compiler_test.dart
T
sra@google.com 28dd6944b7 First cut at extending native classes.
Subclasses of native classes have to be treated largely like native classes since they require interceptors.

The ugly part is collecting the set of subclasses of native classes without resolving all classes.  Only plausible classes are resolved.  Plausible classes have a superclass name that is native class (or subclass of native class).  The name-keyed graph is collected and inverted to identify the true subclasses of native classes.

Things that are missing from this CL:

1. I discussed with Peter a better way of finding which classes are subclasses of native classes by resolving the superclass.  Peter's proposal will still require the graph inversion step but should be more precise.

2. It would be a good idea to replace the 'defineNativeSubclass' calls with more declarative static data on the class and post-process the classes.

3. We need to make sure that fields of subclasses of native classes do not conflict with any (potentially undeclared) properties of the base native class.

4. The compiler should do additional checking
   - The constructor must be a factory constructor.
   - No fields can have initializers.

R=ahe@google.com

Review URL: https://codereview.chromium.org//15026006

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@26208 260f80e4-7a28-3924-810f-c04153c831b5
2013-08-15 19:09:12 +00:00

118 lines
2.9 KiB
Dart

// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=
// VMOptions=--print-object-histogram
// Smoke test of the dart2js compiler API.
library dummy_compiler;
import 'dart:async';
import '../../sdk/lib/_internal/compiler/compiler.dart';
Future<String> provider(Uri uri) {
String source;
if (uri.scheme == "main") {
source = "main() {}";
} else if (uri.scheme == "lib") {
if (uri.path.endsWith("/core.dart")) {
source = """
library core;
class Object {
Object();
operator==(other) {}
get hashCode => throw 'Object.hashCode not implemented.';
}
class Type {}
class bool {}
class num {}
class int {}
class double{}
class String{}
class Function{}
class List {}
class Map {}
class Closure {}
class BoundClosure {}
class Dynamic_ {}
class Null {}
class StackTrace {}
class LinkedHashMap {}
identical(a, b) => true;
getRuntimeTypeInfo(o) {}
setRuntimeTypeInfo(o, i) {}
eqNull(a) {}
eqNullB(a) {}""";
} else if (uri.path.endsWith('_patch.dart')) {
source = '';
} else if (uri.path.endsWith('interceptors.dart')) {
source = """
class Interceptor {
operator==(other) {}
get hashCode => throw 'Interceptor.hashCode not implemented.';
}
class JSIndexable {
get length;
}
class JSMutableIndexable {}
class JSArray implements JSIndexable {
var removeLast;
var add;
}
class JSMutableArray extends JSArray {}
class JSFixedArray extends JSMutableArray {}
class JSExtendableArray extends JSMutableArray {}
class JSString implements JSIndexable {
var split;
var concat;
var toString;
}
class JSFunction {}
class JSInt {}
class JSDouble {}
class JSNumber {}
class JSNull {}
class JSBool {}
getInterceptor(o){}
getDispatchProperty(o) {}
setDispatchProperty(o, v) {}
var mapTypeToInterceptor;""";
} else if (uri.path.endsWith('js_helper.dart')) {
source = 'library jshelper; class JSInvocationMirror {} '
'class ConstantMap {} class TypeImpl {} '
'createRuntimeType(String name) => null;';
} else if (uri.path.endsWith('isolate_helper.dart')) {
source = 'library isolatehelper; class _WorkerStub {}';
} else {
source = "library lib;";
}
} else {
throw "unexpected URI $uri";
}
return new Future.value(source);
}
void handler(Uri uri, int begin, int end, String message, Diagnostic kind) {
if (uri == null) {
print('$kind: $message');
} else {
print('$uri:$begin:$end: $kind: $message');
}
}
main() {
Future<String> result =
compile(new Uri(scheme: 'main'),
new Uri(scheme: 'lib', path: '/'),
new Uri(scheme: 'package', path: '/'),
provider, handler);
result.then((String code) {
if (code == null) {
throw 'Compilation failed';
}
}, onError: (e) {
throw 'Compilation failed';
});
}