| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 } |
| OLD | NEW |