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

Unified Diff: dart/frog/leg/native_handler.dart

Issue 9568008: Do not allow native syntax on all libraries. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « dart/frog/leg/compiler.dart ('k') | dart/frog/leg/scanner/class_element_parser.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dart/frog/leg/native_handler.dart
===================================================================
--- dart/frog/leg/native_handler.dart (revision 4858)
+++ dart/frog/leg/native_handler.dart (working copy)
@@ -11,40 +11,58 @@
#import('tree/tree.dart');
#import('util/util.dart');
-void processNativeClasses(Compiler compiler,
- CompilationUnitElement compilationUnit) {
- for (Link<Element> link = compilationUnit.topLevelElements;
- !link.isEmpty(); link = link.tail) {
- Element element = link.head;
- if (element.kind == ElementKind.CLASS) {
- ClassElement classElement = element;
- if (classElement.isNative()) {
- compiler.registerInstantiatedClass(classElement);
- // Also parse the node to know all its methods because
- // otherwise it will only be parsed if there is a call to
- // one of its constructor.
- element.parseNode(compiler);
- // Resolve to setup the inheritance.
- element.resolve(compiler);
+class NativeHandler extends CompilerTask {
+ NativeHandler(Compiler compiler)
+ : allowedLibraries = new Set<LibraryElement>(),
+ super(compiler);
+
+ Set<LibraryElement> allowedLibraries;
+
+ void processNativeClasses(CompilationUnitElement compilationUnit) {
+ return measure(() {
+ for (Link<Element> link = compilationUnit.topLevelElements;
+ !link.isEmpty(); link = link.tail) {
+ Element element = link.head;
+ if (element.kind == ElementKind.CLASS) {
+ ClassElement classElement = element;
+ if (classElement.isNative()) {
+ compiler.registerInstantiatedClass(classElement);
+ // Also parse the node to know all its methods because
+ // otherwise it will only be parsed if there is a call to
+ // one of its constructor.
+ element.parseNode(compiler);
+ // Resolve to setup the inheritance.
+ element.resolve(compiler);
+ }
+ }
}
+ });
+ }
+
+ void checkNativeSupport(LibraryElement library, Uri uri) {
+ String libraryName = uri.toString();
+ if (library.script.name.contains('dart/frog/tests/native/src')
+ || libraryName == 'dart:dom'
+ || libraryName == 'dart:html') {
+ allowedLibraries.add(library);
+ library.define(new ForeignElement(
+ const SourceString('native'), library), compiler);
}
}
}
-void checkNativeSupport(Compiler compiler,
- LibraryElement library,
- Uri uri) {
- String libraryName = uri.toString();
- if (library.script.name.contains('dart/frog/tests/native/src')
- || libraryName == 'dart:dom'
- || libraryName == 'dart:html') {
- library.define(new ForeignElement(
- const SourceString('native'), library), compiler);
+
+void checkAllowedLibrary(ElementListener listener, Token token) {
ahe 2012/03/06 08:12:44 Extracting the compiler from the ElementListener i
ngeoffray 2012/03/06 12:48:49 Unfortunately, this does not work that well. See l
ahe 2012/03/06 13:08:30 It will work fine. We can do a VC and I can explai
+ Compiler compiler = listener.listener;
+ LibraryElement currentLibrary = listener.compilationUnitElement.getLibrary();
+ if (!compiler.nativeHandler.allowedLibraries.contains(currentLibrary)) {
+ listener.unexpected(token);
}
}
-Token handleNativeBlockToSkip(Listener listener, Token token) {
- token = token.next;
+Token handleNativeBlockToSkip(ElementListener listener, Token token) {
+ checkAllowedLibrary(listener, token);
+ token = token.next;
if (token.kind === STRING_TOKEN) {
token = token.next;
}
@@ -56,6 +74,7 @@
}
Token handleNativeClassBodyToSkip(Listener listener, Token token) {
+ checkAllowedLibrary(listener, token);
listener.handleIdentifier(token);
token = token.next;
if (token.kind !== STRING_TOKEN) {
@@ -71,6 +90,7 @@
}
Token handleNativeClassBody(Listener listener, Token token) {
+ checkAllowedLibrary(listener, token);
token = token.next;
if (token.kind !== STRING_TOKEN) {
listener.unexpected(token);
@@ -81,6 +101,7 @@
}
Token handleNativeFunctionBody(ElementListener listener, Token token) {
+ checkAllowedLibrary(listener, token);
Token begin = token;
listener.beginExpressionStatement(token);
listener.handleIdentifier(token);
« no previous file with comments | « dart/frog/leg/compiler.dart ('k') | dart/frog/leg/scanner/class_element_parser.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698