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

Side by Side 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, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « dart/frog/leg/elements/elements.dart ('k') | dart/frog/leg/scanner/class_element_parser.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #library('native'); 5 #library('native');
6 #import('../../lib/uri/uri.dart'); 6 #import('../../lib/uri/uri.dart');
7 #import('leg.dart'); 7 #import('leg.dart');
8 #import('elements/elements.dart'); 8 #import('elements/elements.dart');
9 #import('scanner/scannerlib.dart'); 9 #import('scanner/scannerlib.dart');
10 #import('ssa/ssa.dart'); 10 #import('ssa/ssa.dart');
(...skipping 13 matching lines...) Expand all
24 // otherwise it will only be parsed if there is a call to 24 // otherwise it will only be parsed if there is a call to
25 // one of its constructor. 25 // one of its constructor.
26 element.parseNode(compiler); 26 element.parseNode(compiler);
27 // Resolve to setup the inheritance. 27 // Resolve to setup the inheritance.
28 element.resolve(compiler); 28 element.resolve(compiler);
29 } 29 }
30 } 30 }
31 } 31 }
32 } 32 }
33 33
34 void checkNativeSupport(Compiler compiler, 34 void maybeEnableNative(Compiler compiler,
35 LibraryElement library, 35 LibraryElement library,
36 Uri uri) { 36 Uri uri) {
37 String libraryName = uri.toString(); 37 String libraryName = uri.toString();
38 if (library.script.name.contains('dart/frog/tests/native/src') 38 if (library.script.name.contains('dart/frog/tests/native/src')
39 || libraryName == 'dart:dom' 39 || libraryName == 'dart:dom'
40 || libraryName == 'dart:html') { 40 || libraryName == 'dart:html') {
41 library.define(new ForeignElement( 41 library.define(new ForeignElement(
42 const SourceString('native'), library), compiler); 42 const SourceString('native'), library), compiler);
43 library.canUseNative = true;
44 }
45 }
46
47 void checkAllowedLibrary(ElementListener listener, Token token) {
48 LibraryElement currentLibrary = listener.compilationUnitElement.getLibrary();
49 if (!currentLibrary.canUseNative) {
50 listener.recoverableError(token);
43 } 51 }
44 } 52 }
45 53
46 Token handleNativeBlockToSkip(Listener listener, Token token) { 54 Token handleNativeBlockToSkip(Listener listener, Token token) {
47 token = token.next; 55 checkAllowedLibrary(listener, token);
56 token = token.next;
48 if (token.kind === STRING_TOKEN) { 57 if (token.kind === STRING_TOKEN) {
49 token = token.next; 58 token = token.next;
50 } 59 }
51 if (token.stringValue === '{') { 60 if (token.stringValue === '{') {
52 BeginGroupToken beginGroupToken = token; 61 BeginGroupToken beginGroupToken = token;
53 token = beginGroupToken.endGroup; 62 token = beginGroupToken.endGroup;
54 } 63 }
55 return token; 64 return token;
56 } 65 }
57 66
58 Token handleNativeClassBodyToSkip(Listener listener, Token token) { 67 Token handleNativeClassBodyToSkip(Listener listener, Token token) {
68 checkAllowedLibrary(listener, token);
59 listener.handleIdentifier(token); 69 listener.handleIdentifier(token);
60 token = token.next; 70 token = token.next;
61 if (token.kind !== STRING_TOKEN) { 71 if (token.kind !== STRING_TOKEN) {
62 return listener.unexpected(token); 72 return listener.unexpected(token);
63 } 73 }
64 token = token.next; 74 token = token.next;
65 if (token.stringValue !== '{') { 75 if (token.stringValue !== '{') {
66 return listener.unexpected(token); 76 return listener.unexpected(token);
67 } 77 }
68 BeginGroupToken beginGroupToken = token; 78 BeginGroupToken beginGroupToken = token;
69 token = beginGroupToken.endGroup; 79 token = beginGroupToken.endGroup;
70 return token; 80 return token;
71 } 81 }
72 82
73 Token handleNativeClassBody(Listener listener, Token token) { 83 Token handleNativeClassBody(Listener listener, Token token) {
84 checkAllowedLibrary(listener, token);
74 token = token.next; 85 token = token.next;
75 if (token.kind !== STRING_TOKEN) { 86 if (token.kind !== STRING_TOKEN) {
76 listener.unexpected(token); 87 listener.unexpected(token);
77 } else { 88 } else {
78 token = token.next; 89 token = token.next;
79 } 90 }
80 return token; 91 return token;
81 } 92 }
82 93
83 Token handleNativeFunctionBody(ElementListener listener, Token token) { 94 Token handleNativeFunctionBody(ElementListener listener, Token token) {
95 checkAllowedLibrary(listener, token);
84 Token begin = token; 96 Token begin = token;
85 listener.beginExpressionStatement(token); 97 listener.beginExpressionStatement(token);
86 listener.handleIdentifier(token); 98 listener.handleIdentifier(token);
87 token = token.next; 99 token = token.next;
88 if (token.kind === STRING_TOKEN) { 100 if (token.kind === STRING_TOKEN) {
89 listener.beginLiteralString(token); 101 listener.beginLiteralString(token);
90 listener.endLiteralString(0); 102 listener.endLiteralString(0);
91 listener.pushNode(new NodeList.singleton(listener.popNode())); 103 listener.pushNode(new NodeList.singleton(listener.popNode()));
92 listener.endSend(token); 104 listener.endSend(token);
93 token = token.next; 105 token = token.next;
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 } else if (!node.arguments.tail.isEmpty()) { 245 } else if (!node.arguments.tail.isEmpty()) {
234 builder.compiler.cancel('More than one argument to native'); 246 builder.compiler.cancel('More than one argument to native');
235 } else { 247 } else {
236 LiteralString jsCode = node.arguments.head; 248 LiteralString jsCode = node.arguments.head;
237 int start = jsCode.value.slowToString()[0] === '@' ? 1 : 0; 249 int start = jsCode.value.slowToString()[0] === '@' ? 1 : 0;
238 builder.push(new HForeign(builder.unquote(jsCode, start), 250 builder.push(new HForeign(builder.unquote(jsCode, start),
239 const SourceString('Object'), 251 const SourceString('Object'),
240 <HInstruction>[])); 252 <HInstruction>[]));
241 } 253 }
242 } 254 }
OLDNEW
« no previous file with comments | « dart/frog/leg/elements/elements.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